Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically add tabs to TabControl container

I have a form in which I would like to be able to add tabs dynamically through the use of a button (much like the buttons most modern browsers have for adding tabs). These tabs should also contain a text box which is stretched to the individual tab's width and height upon creation.

I apologise for the lack of code but besides instantiating a TabControl container within a Form class, I have no clue as to what I should do next.

Thanks in advance.

like image 819
AutomEng Avatar asked Oct 11 '15 20:10

AutomEng


1 Answers

All you need is to call the Add method on the TabControl.TabPages collection, then add other controls to that TabPage, like so:

    private void button1_Click(object sender, EventArgs e)
    {
        TabPage tp = new TabPage("Test");
        tabControl1.TabPages.Add(tp);

        TextBox tb = new TextBox();
        tb.Dock = DockStyle.Fill;
        tb.Multiline = true;

        tp.Controls.Add(tb);


    }

Hope this helps

like image 52
Luc Morin Avatar answered Oct 03 '22 23:10

Luc Morin