Dynamically add tabs to TabControl container

笑着哭i 提交于 2020-01-03 09:09:34

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/33069634/dynamically-add-tabs-to-tabcontrol-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!