Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TabControl.TabPageCollection.Clear Method

Removes all the tab pages from the collection.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public virtual void Clear()

Implements

IList.Clear()

The following code example initially creates a TabControl with three TabPage. This example uses the Clear method to clear all controls in the tabControl1 controls collection at one instance. Then, the example adds tabPage2 back to the collection. Notice that the TabPages property is used to get the tabControl1 controls collection to remove (and add) tab pages from this 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;

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

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

        // Removes all the tab pages from tabControl1. 
        this.tabControl1.TabPages.Clear();

        // Adds the tabPage1 back to tabControl1. 
        this.tabControl1.TabPages.Add(tabPage2);

        this.tabControl1.Location = new Point(25, 25);
        this.tabControl1.Size = new Size(250, 250);
        this.ClientSize = new Size(300, 300);
        this.Controls.Add(tabControl1);
    }

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.