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 System.Windows.Forms.dll)

public class TabControl : Control

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 .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 : 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.

    // 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.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";
        tab1Button1.Click += new 
        this.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.

    private void tab1Button1_Click (object sender, System.EventArgs e)
        // Inserts the code that should run when the button is clicked.

    public static void Main(string[] args) 
        Application.Run(new 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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0