When adding any control dynamically, first create an instance of the control
TabControl tc = new TabControl();
Then you will probably need to position it and change some other properties e.g.
tc.Top = 145;
tc.Left = 150;
tc.Name = "DynamicTabControl";
Add some tab pages to it...
tc.TabPages.Add("My 1st Tab");
tc.TabPages.Add("My 2nd Tab");
You will probably want to add some event handlers too, so that you know when you have moved between tabs for example
tc.SelectedIndexChanged += new System.EventHandler(tabControl1_SelectedIndexChanged);
And you need to remember to add it to the controls collection for the form
this.Controls.Add(tc);
Here's an example of that event handler I set up
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
TabControl tc1 = (TabControl)sender;
MessageBox.Show(tc1.SelectedIndex.ToString());
}
If you want to add further tabs later on see
reference[
^]
An example:
private void button3_Click(object sender, EventArgs e)
{
TabControl tc1 = (TabControl)this.Controls.Find("DynamicTabControl", true)[0];
tc1.TabPages.Add("A 3rd Tab");
}