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



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.

        // Adds the tabPage1 back to tabControl1.

        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