System.Windows.Forms Namesp ...


.NET Framework Class Library
TabPage Class

Represents a single tab page in a TabControl.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Syntax

Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class TabPage _
    Inherits Panel
Visual Basic (Usage)
Dim instance As TabPage
C#
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class TabPage : Panel
Visual C++
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class TabPage : public Panel
JScript
public class TabPage extends Panel
Remarks

TabPage controls represent the tabbed pages in a TabControl control. The order of tab pages in the TabControl..::.TabPages collection reflects the order of tabs in the TabControl control. To change the order of tabs in the control, you must change their positions in the collection by removing them and inserting them at new indexes.

TabPage controls are constrained by their container, so some of the properties inherited from the Control base class will have no effect, including Top, Height, Left, Width, Show, and Hide.

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.

NoteNote:

In .NET Framework version 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.

For more information about how this control responds to the Focus and Select methods, see the following Control members: CanFocus, CanSelect, Focused, ContainsFocus, Focus, Select.

NoteNote:

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.

In .NET Framework version 2.0, the UseVisualStyleBackColor property lets you indicate whether the background of the tab page should render using the current visual style. This occurs only when the UseVisualStyleBackColor and Application..::.RenderWithVisualStyles property values are both true and the Appearance property of the parent TabControl is Normal. Otherwise, the background is painted normally.

Examples

The following code example creates a TabControl with one TabPage.

Use the System.Drawing and System.Windows.Forms namespaces for this example.

Visual Basic
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Inherits Form
    Private tabControl1 As TabControl

    ' Declares tabPage1 as a TabPage type.
    Private tabPage1 As System.Windows.Forms.TabPage

    Private Sub MyTabs()
        Me.tabControl1 = New TabControl()

        ' Invokes the TabPage() constructor to create the tabPage1.
        Me.tabPage1 = New System.Windows.Forms.TabPage()

        Me.tabControl1.Controls.AddRange(New Control() {Me.tabPage1})
        Me.tabControl1.Location = New Point(25, 25)
        Me.tabControl1.Size = New Size(250, 250)

        Me.ClientSize = New Size(300, 300)
        Me.Controls.AddRange(New Control() {Me.tabControl1})
    End Sub

    Public Sub New()
        MyTabs()
    End Sub

    Shared Sub Main()
        Application.Run(New Form1())
    End Sub
End Class
C#
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
{
    private TabControl tabControl1;

    // Declares tabPage1 as a TabPage type.
    private System.Windows.Forms.TabPage tabPage1;

    private void MyTabs()
    {
        this.tabControl1 = new TabControl();

        // Invokes the TabPage() constructor to create the tabPage1.
        this.tabPage1 = new System.Windows.Forms.TabPage();

        this.tabControl1.Controls.AddRange(new Control[] {
            this.tabPage1});
        this.tabControl1.Location = new Point(25, 25);
        this.tabControl1.Size = new Size(250, 250);

        this.ClientSize = new Size(300, 300);
        this.Controls.AddRange(new Control[] {
            this.tabControl1});
    }

    public Form1()
    {
        MyTabs();
    }

    static void Main() 
    {
        Application.Run(new Form1());
    }
}
Visual C++
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public Form
{
private:
   TabControl^ tabControl1;

   // Declares tabPage1 as a TabPage type.
   System::Windows::Forms::TabPage^ tabPage1;
   void MyTabs()
   {
      this->tabControl1 = gcnew TabControl;

      // Invokes the TabPage() constructor to create the tabPage1.
      this->tabPage1 = gcnew System::Windows::Forms::TabPage;
      array<Control^>^tabControls = {this->tabPage1};
      this->tabControl1->Controls->AddRange( tabControls );
      this->tabControl1->Location = Point(25,25);
      this->tabControl1->Size = System::Drawing::Size( 250, 250 );
      this->ClientSize = System::Drawing::Size( 300, 300 );
      array<Control^>^formControls = {this->tabControl1};
      this->Controls->AddRange( formControls );
   }


public:
   Form1()
   {
      MyTabs();
   }

};

int main()
{
   Application::Run( gcnew Form1 );
}

Inheritance Hierarchy

System..::.Object
  System..::.MarshalByRefObject
    System.ComponentModel..::.Component
      System.Windows.Forms..::.Control
        System.Windows.Forms..::.ScrollableControl
          System.Windows.Forms..::.Panel
            System.Windows.Forms..::.TabPage
Thread Safety

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

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.
Version Information

.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
See Also

Reference

TabPage
Tags :


Community Content

shentho
Hide / Show Tabpages in C#

Since the Hide() / Show() methods are not functional in C#2.x , we have to find a work arround.

Simple workarround:

/* In the Form_Load() method hide the tab ( if you wish to initialy hide the tab) assuming the name of the tab page is TP */
tabControl1.TabPages.Remove(TP);

/* if you want to show the tab page add to the end */
tabControl1.TabPages.Add(TP);

or

/* if you want it to always be the second tab for example */
tabControl1.TabPages.Insert(1,TP);

Have fun Tabbing!


Page view tracker