TabControl.TabPageCollection.IndexOf Method (TabPage)

 

Returns the index of the specified tab page in the collection.

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

public int IndexOf(
	TabPage page
)

Parameters

page
Type: System.Windows.Forms.TabPage

The TabPage to locate in the collection.

Return Value

Type: System.Int32

The zero-based index of the tab page; -1 if it cannot be found.

Exception Condition
ArgumentNullException

The value of page is null.

The following code example creates a TabControl with one TabPage. This example uses the IndexOf method to retrieve the tabPage1 index value. A ToolTip is used to display this value.

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;

    public Form1()
    {
        this.tabControl1 = new TabControl();
        this.tabPage1 = new TabPage("myTabPage");

        this.tabControl1.TabPages.Add(tabPage1);
        this.tabControl1.ShowToolTips = true;
        this.tabControl1.Location = new Point(25, 25);
        this.tabControl1.Size = new Size(250, 250);

        this.tabPage1.ToolTipText = "TabIndex = " +

            // Gets the tabPage1 TabIndex value from the tabControl1 controls collection.
            // Converts the tabPage1 TabIndex value to a string.
            (tabControl1.TabPages.IndexOf(tabPage1)).ToString();

        this.ClientSize = new Size(300, 300);
        this.Controls.Add(tabControl1);
    }

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

.NET Framework
Available since 1.1
Return to top
Show: