TabControl.TabPageCollection.Contains Method (TabPage)


Determines whether a specified tab page is in the collection.

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

public bool Contains(
	TabPage page


Type: System.Windows.Forms.TabPage

The TabPage to locate in the collection.

Return Value

Type: System.Boolean

true if the specified TabPage is in the collection; otherwise, false.

Exception Condition

The value of page is null.

The following code example initially creates a TabControl with three TabPage objects. The first two tab pages are added directly to tabControl1 by the AddRange method. The Contains method determines tabPage3 is part of the tabControl1 controls collection. Because tabPage3 was not found in this collection, it was added by the Add method.

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;

    public Form1()
        this.tabControl1 = new TabControl();
        string[] tabText = {"tabPage1", "tabPage2", "tabPage3"};
        this.tabPage1 = new TabPage(tabText[0]);
        this.tabPage2 = new TabPage(tabText[1]);
        this.tabPage3 = new TabPage(tabText[2]);

        // Populates the tabControl1 with two tab pages.
        this.tabControl1.TabPages.AddRange(new TabPage[] {
            tabPage1, tabPage2});

        // Checks the tabControl1 controls collection for tabPage3.
        // Adds tabPage3 to tabControl1 if it is not in the collection.
        if (tabControl1.TabPages.Contains(tabPage3) == false)

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

        this.ClientSize = new Size(300, 300);

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

.NET Framework
Available since 1.1
Return to top