This documentation is archived and is not being maintained.

TabControl Class

Manages a related set of tab pages.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class TabControl
	Inherits Control
Dim instance As TabControl

/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class TabControl extends Control
public class TabControl extends Control
Not applicable.

A TabControl contains tab pages, which are represented by TabPage objects that you add through the TabPages property. The order of tab pages in this collection reflects the order the tabs appear in the control.

The user can change the current TabPage by clicking one of the tabs in the control. You can also programmatically change the current TabPage by using one of the following TabControl properties:

In Microsoft .NET Framework version 2.0, you can also use one of the following methods:

In .NET Framework 2.0, you can respond when the current tab changes by handling one of the following events:

The tabs in a TabControl are part of the TabControl, but not parts of the individual TabPage controls. Members of the TabPage class, such as the ForeColor property, affect only the client rectangle of the tab page, but not the tabs. Additionally, the Hide method of the TabPage will not hide the tab. To hide the tab, you must remove the TabPage control from the TabControl.TabPages collection.

In .NET Framework 2.0, the tab is considered part of the tab page for determining when the Enter and Leave events of the TabPage occur. In earlier versions of the .NET Framework, the Enter and Leave events of the TabPage do not occur when focus enters or leaves a tab, but only when focus enters or leaves the client rectangle of the tab page.

The following events are not raised for the TabControl class unless there is at least one TabPage in the TabControl.TabPages collection: Control.Click, Control.DoubleClick, Control.MouseDown, Control.MouseUp, Control.MouseHover, Control.MouseEnter, Control.MouseLeave and Control.MouseMove. If there is at least one TabPage in the collection, and the user interacts with the tab control's header (where the TabPage names appear), the TabControl raises the appropriate event. However, if the user interaction is within the ClientRectangle of the tab page, the TabPage raises the appropriate event.

Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown.

When visual styles are enabled, and the Alignment property is set to a value other than Top, the tab contents might not render correctly. To work around this issue, you can paint the tab contents yourself using owner drawing. For more information, see How to: Display Side-Aligned Tabs with TabControl.

When the Alignment property is set to a value other than Top and the Appearance property is set to a value other than Normal, the tab page contents might not render correctly.

The following code example uses the Visual Studio .NET Windows Forms Designer to create a TabControl with three tab pages. Each tab page contains several controls.

Public Class Form1
    Inherits System.Windows.Forms.Form
    ' Required designer variable.
    Private components As System.ComponentModel.Container
    ' Declares variables.
    Private tab3RadioButton2 As System.Windows.Forms.RadioButton
    Private tab3RadioButton1 As System.Windows.Forms.RadioButton
    Private tab2CheckBox3 As System.Windows.Forms.CheckBox
    Private tab2CheckBox2 As System.Windows.Forms.CheckBox
    Private tab2CheckBox1 As System.Windows.Forms.CheckBox
    Private tab1Label1 As System.Windows.Forms.Label
    Private WithEvents tab1Button1 As System.Windows.Forms.Button
    Private tabPage3 As System.Windows.Forms.TabPage
    Private tabPage2 As System.Windows.Forms.TabPage
    Private tabPage1 As System.Windows.Forms.TabPage
    Private tabControl1 As System.Windows.Forms.TabControl    
    Public Sub New()
        ' This call is required for Windows Form Designer support.
    End Sub    
    ' This method is required for Designer support.
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.tabPage1 = New System.Windows.Forms.TabPage()
        Me.tab2CheckBox3 = New System.Windows.Forms.CheckBox()
        Me.tab3RadioButton2 = New System.Windows.Forms.RadioButton()
        Me.tabControl1 = New System.Windows.Forms.TabControl()
        Me.tab2CheckBox2 = New System.Windows.Forms.CheckBox()
        Me.tab2CheckBox1 = New System.Windows.Forms.CheckBox()
        Me.tab3RadioButton1 = New System.Windows.Forms.RadioButton()
        Me.tab1Label1 = New System.Windows.Forms.Label()
        Me.tabPage3 = New System.Windows.Forms.TabPage()
        Me.tabPage2 = New System.Windows.Forms.TabPage()
        Me.tab1Button1 = New System.Windows.Forms.Button()
        tabPage1.Text = "tabPage1"
        tabPage1.Size = New System.Drawing.Size(256, 214)
        tabPage1.TabIndex = 0
        tab2CheckBox3.Location = New System.Drawing.Point(32, 136)
        tab2CheckBox3.Text = "checkBox3"
        tab2CheckBox3.Size = New System.Drawing.Size(176, 32)
        tab2CheckBox3.TabIndex = 2
        tab2CheckBox3.Visible = True
        tab3RadioButton2.Location = New System.Drawing.Point(40, 72)
        tab3RadioButton2.Text = "radioButton2"
        tab3RadioButton2.Size = New System.Drawing.Size(152, 24)
        tab3RadioButton2.TabIndex = 1
        tab3RadioButton2.Visible = True
        tabControl1.Location = New System.Drawing.Point(16, 16)
        tabControl1.Size = New System.Drawing.Size(264, 240)
        tabControl1.SelectedIndex = 0
        tabControl1.TabIndex = 0
        tab2CheckBox2.Location = New System.Drawing.Point(32, 80)
        tab2CheckBox2.Text = "checkBox2"
        tab2CheckBox2.Size = New System.Drawing.Size(176, 32)
        tab2CheckBox2.TabIndex = 1
        tab2CheckBox2.Visible = True
        tab2CheckBox1.Location = New System.Drawing.Point(32, 24)
        tab2CheckBox1.Text = "checkBox1"
        tab2CheckBox1.Size = New System.Drawing.Size(176, 32)
        tab2CheckBox1.TabIndex = 0
        tab3RadioButton1.Location = New System.Drawing.Point(40, 32)
        tab3RadioButton1.Text = "radioButton1"
        tab3RadioButton1.Size = New System.Drawing.Size(152, 24)
        tab3RadioButton1.TabIndex = 0
        tab1Label1.Location = New System.Drawing.Point(16, 24)
        tab1Label1.Text = "label1"
        tab1Label1.Size = New System.Drawing.Size(224, 96)
        tab1Label1.TabIndex = 1
        tabPage3.Text = "tabPage3"
        tabPage3.Size = New System.Drawing.Size(256, 214)
        tabPage3.TabIndex = 2
        tabPage2.Text = "tabPage2"
        tabPage2.Size = New System.Drawing.Size(256, 214)
        tabPage2.TabIndex = 1
        tab1Button1.Location = New System.Drawing.Point(88, 144)
        tab1Button1.Size = New System.Drawing.Size(80, 40)
        tab1Button1.TabIndex = 0
        tab1Button1.Text = "button1"
        Me.Text = "Form1"
        ' Adds controls to the second tab page.
        ' Adds controls to the third tab page.
        ' Adds controls to the first tab page.
        ' Adds the TabControl to the form.
        ' Adds the tab pages to the TabControl.
    End Sub   
    Private Sub tab1Button1_Click(sender As Object, e As System.EventArgs) _
        Handles tab1Button1.Click
        ' Inserts the code that should run when the button is clicked.
    End Sub
    Public Shared Sub Main()
        Application.Run(New Form1())
    End Sub
End Class

public class Form1 extends System.Windows.Forms.Form
    // Required designer variable.
    private System.ComponentModel.Container components;

    // Declare variables.
    private System.Windows.Forms.RadioButton tab3RadioButton2;
    private System.Windows.Forms.RadioButton tab3RadioButton1;
    private System.Windows.Forms.CheckBox tab2CheckBox3;
    private System.Windows.Forms.CheckBox tab2CheckBox2;
    private System.Windows.Forms.CheckBox tab2CheckBox1;
    private System.Windows.Forms.Label tab1Label1;
    private System.Windows.Forms.Button tab1Button1;
    private System.Windows.Forms.TabPage tabPage3;
    private System.Windows.Forms.TabPage tabPage2;
    private System.Windows.Forms.TabPage tabPage1;
    private System.Windows.Forms.TabControl tabControl1;

    public Form1()
        // This call is required for Windows Form Designer support.
    } //Form1

    // This method is required for Designer support.
    private void InitializeComponent()
        this.components = new System.ComponentModel.Container();
        this.tabPage1 = new System.Windows.Forms.TabPage();
        this.tab2CheckBox3 = new System.Windows.Forms.CheckBox();
        this.tab3RadioButton2 = new System.Windows.Forms.RadioButton();
        this.tabControl1 = new System.Windows.Forms.TabControl();
        this.tab2CheckBox2 = new System.Windows.Forms.CheckBox();
        this.tab2CheckBox1 = new System.Windows.Forms.CheckBox();
        this.tab3RadioButton1 = new System.Windows.Forms.RadioButton();
        this.tab1Label1 = new System.Windows.Forms.Label();
        this.tabPage3 = new System.Windows.Forms.TabPage();
        this.tabPage2 = new System.Windows.Forms.TabPage();
        this.tab1Button1 = new System.Windows.Forms.Button();
        tabPage1.set_Size(new System.Drawing.Size(256, 214));
        tab2CheckBox3.set_Location(new System.Drawing.Point(32, 136));
        tab2CheckBox3.set_Size(new System.Drawing.Size(176, 32));
        tab3RadioButton2.set_Location(new System.Drawing.Point(40, 72));
        tab3RadioButton2.set_Size(new System.Drawing.Size(152, 24));
        tabControl1.set_Location(new System.Drawing.Point(16, 16));
        tabControl1.set_Size(new System.Drawing.Size(264, 240));
        tab2CheckBox2.set_Location(new System.Drawing.Point(32, 80));
        tab2CheckBox2.set_Size(new System.Drawing.Size(176, 32));
        tab2CheckBox1.set_Location(new System.Drawing.Point(32, 24));
        tab2CheckBox1.set_Size(new System.Drawing.Size(176, 32));
        tab3RadioButton1.set_Location(new System.Drawing.Point(40, 32));
        tab3RadioButton1.set_Size(new System.Drawing.Size(152, 24));
        tab1Label1.set_Location(new System.Drawing.Point(16, 24));
        tab1Label1.set_Size(new System.Drawing.Size(224, 96));
        tabPage3.set_Size(new System.Drawing.Size(256, 214));
        tabPage2.set_Size(new System.Drawing.Size(256, 214));
        tab1Button1.set_Location(new System.Drawing.Point(88, 144));
        tab1Button1.set_Size(new System.Drawing.Size(80, 40));
        tab1Button1.add_Click(new System.EventHandler(this.tab1Button1_Click));

        // Adds controls to the second tab page.

        // Adds controls to the third tab page.

        // Adds controls to the first tab page.

        // Adds the TabControl to the form.

        // Adds the tab pages to the TabControl.
    } //InitializeComponent

    private void tab1Button1_Click(Object sender, System.EventArgs e)
        // Inserts the code that should run when the button is clicked.
    } //tab1Button1_Click
    public static void main(String[] args)
        Application.Run(new Form1());
    } //main
} //Form1


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0