TabControl is made from two parts:

  1. TabItem which represents the actual tab that contains image and text
  2. TabControlPanel which is connected to the tab through TabItem.AttachedControl property and which hosts your controls

The easiest way to add the tab and associated panels is by using the TabControl.CreateTab method. It will return the reference to the TabItem object and you can use then TabItem.AttachedControl property to access the tab panel. To the panel then you can add your controls for example like this TabItem.AttachedControl.Controls.Add(myControl). Here is sample code:


TabItem newTab = tabControl1.CreateTab("New Tab");
TabControlPanel panel = (TabControlPanel)newTab.AttachedControl;
TextBox textBox = new TextBox();
textBox.Location = new Point(10, 10);


Dim newTab As TabItem = tabControl1.CreateTab("New Tab")
Dim panel As TabControlPanel = DirectCast(newTab.AttachedControl, TabControlPanel)
Dim textBox As New TextBox()
textBox.Location = New Point(10, 10)

To select a tab item using code:


tabControl1.SelectedTabIndex = 1;


tabControl1.SelectedTabIndex = 1

To remove tabs remove TabItem from the TabControl.Tabs collection and remove the TabControl.Controls.Remove(tabItem.AttachedControl)


TabItem itemToRemove = tabControl1.Tabs[1];


Dim itemToRemove As TabItem = tabControl1.Tabs(1)

Great source of information is also InitializeComponent method inside of your form. If you drop the TabControl onto the form and set it up the way you want it to appear with controls and everything else, you can explore the InitializeComponent method on the form which will contain all the code to create what you see on the screen.

Related posts:

  1. How to change TabControl tab and panel colors
  2. How To Create NavigationPane Buttons Using Code
  3. How to Create Menu Using Code
  4. How to Create Toolbars Using Code
  5. What is InitializeComponent() method and how to use it to learn how to create controls from code