Export (0) Print
Expand All

TabControl.TabPageCollection.Count Property

Gets the number of tab pages in the collection.

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

[BrowsableAttribute(false)]
public int Count { get; }

Property Value

Type: System.Int32
The number of tab pages in the collection.

Implements

ICollection.Count

The following code example creates a TabControl with three TabPage. The Count property gets the number of TabPage objects in the tabControl1 controls collection.

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;
    private TabPage tabPage1;
    private TabPage tabPage2;
    private TabPage tabPage3;
    private Label label1;

    public Form1()
    {
        this.tabControl1 = new TabControl();
        this.tabPage1 = new TabPage();
        this.tabPage2 = new TabPage();
        this.tabPage3 = new TabPage();
        this.label1 = new Label();

        this.tabControl1.TabPages.AddRange(new TabPage[] {
	        tabPage1, tabPage2, tabPage3});

        this.tabControl1.Location = new Point(25, 75);
        this.tabControl1.Size = new Size(250, 200);

        // Gets the number of TabPage objects in the tabControl1 controls collection.  
        int tabCount = tabControl1.TabPages.Count;

        this.label1.Location = new Point(25, 25);
        this.label1.Size = new Size(250, 25);
        this.label1.Text = "The TabControl below has " + tabCount.ToString() +
	        " TabPage objects in its controls collection.";

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

    static void Main() 
    {
        Application.Run(new Form1());
    }
}


.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft