0

Hi,

I have an application with a main form, and a TabControl in the centre. When a user creates a new tab I want to have controls (Textboxes and labels etc) loaded onto the tab.

I was thinking of creating my own class that have these controls already defined in it.
I guess I will have to inherit the Tabpage class, have a custom initializing method to put my controls on-screen?

Then create a new object in the Main form:
CustomTabPage custTabPage = new CustomTabPage();
customTabPage.addControls();

tabControl1.Controls.Add(customTabPage);

I'm just guessing at the moment. Can someone guide me in the right direction?

Thanks

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by johnnyturbo3
0

Hello johnnyturbo3,
You have got right direction. I have tried to recreate your task. Working very well.

class MyTabClass:TabPage
    {

        public MyTabClass()
        {
            TextBox textbox = new TextBox
            {
                Width = 100,
                Height = 25,
                Left = 25,
                Top = 25
            };

            this.Controls.Add(textbox);
        }

    }


/* call from form

     private void button2_Click(object sender, EventArgs e)
        {
            MyTabClass tab = new MyTabClass();
            this.tabControl1.TabPages.Add(tab);
        }

You can set any parameters for your class:
text, name....

Cheers

0

There is an annoyance with the class file that I've create for the custom Tabpage. Because I inherit the System.Windows.Forms.TabPage, Visual Studio thinks that my class is actually a Form, and thus has a Designer View and several warnings etc.

Is there anyway to inherit System.Windows.Forms.TabPage and not make the class think it's a Form?

Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.