问题
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