Export (0) Print
Expand All

Adding and Removing Tabs with the Windows Forms TabControl

Visual Studio .NET 2003

Adding and removing tabs from the Windows Forms TabControl can be done in the designer or with code. You can add or remove tabs at run time as well as at design time.

To add a tab in the designer

  1. Drag a TabControl from the Windows Forms tab of the Toolbox to the designer.
  2. In the Properties window, click the Add Tab link.

    - or -

    In the Properties window, click the Ellipsis button (Aa984280.vbellipsesbutton(en-us,VS.71).gif) next to the TabPages property to open the TabPage Collection Editor. Click the Add button.

To remove a tab in the designer

  • In the Properties window, click the Remove Tab link. This will remove the tab that is displayed topmost in the control.

    - or -

    In the Properties window, click the Ellipsis button (Aa984280.vbellipsesbutton(en-us,VS.71).gif) next to the TabPages property to open the TabPage Collection Editor. In the left-side window, under "Members:", select the tab to remove and click the Remove button.

To add a tab programmatically

  • Use the Add method of the TabPages property.
    ' Visual Basic
    Dim myTabPage As New TabPage()
    myTabPage.Text = "TabPage" & (TabControl1.TabPages.Count + 1)
    TabControl1.TabPages.Add(myTabPage)
    
    // C#
    string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
    TabPage myTabPage = new TabPage(title);
    tabControl1.TabPages.Add(myTabPage);
    
    // C++
    String* title = String::Concat(S"TabPage ",
       (tabControl1->TabCount + 1).ToString());
    TabPage* myTabPage = new TabPage(title);
    tabControl1->TabPages->Add(myTabPage);
    

To remove a tab programmatically

  • Use the Remove method of the TabPages property to remove selected tabs; or to remove all tabs, use the Clear method of the TabPages property.
    ' Visual Basic
    ' Removes the selected tab:
    TabControl1.TabPages.Remove(TabControl1.SelectedTab)
    ' Removes all the tabs:
    TabControl1.TabPages.Clear()
    
    // C#
    // Removes the selected tab:
    tabControl1.TabPages.Remove(tabControl1.SelectedTab);
    // Removes all the tabs:
    tabControl1.TabPages.Clear();
    
    // C++
    // Removes the selected tab:
    tabControl1->TabPages->Remove(tabControl1->SelectedTab);
    // Removes all the tabs:
    tabControl1->TabPages->Clear();
    

See Also

Introduction to the Windows Forms TabControl | Adding a Control to a Tab Page | Disabling Tab Pages Programmatically | Changing the Appearance of the Windows Forms TabControl

Show:
© 2014 Microsoft