Export (0) Print
Expand All
1 out of 7 rated this helpful - Rate this topic

TabPage Class

Represents a single tab page in a TabControl.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class TabPage : Panel
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class TabPage extends Panel
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class TabPage extends Panel

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

The following code example creates a TabControl with one TabPage.

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

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());
    }
}

import System.Drawing.*;
import System.Windows.Forms.*;

public class Form1 extends 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.get_Controls().AddRange(new Control[] {
            this.tabPage1 });
        this.tabControl1.set_Location(new Point(25, 25));
        this.tabControl1.set_Size(new Size(250, 250));

        this.set_ClientSize(new Size(300, 300));
        this.get_Controls().AddRange(new Control[] { this.tabControl1 });
    } //MyTabs

    public Form1()
    {
        MyTabs();
    } //Form1

    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main
} //Form1

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.Panel
            System.Windows.Forms.TabPage
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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.