TabControl.TabPageCollection.AddRange(TabPage[]) Method

Definition

Adds a set of tab pages to the collection.

public void AddRange (System.Windows.Forms.TabPage[] pages);
public void AddRange (params System.Windows.Forms.TabPage[] pages);

Parameters

pages
TabPage[]

An array of type TabPage that contains the tab pages to add.

Exceptions

The value of pages equals null.

Examples

The following code example creates a TabControl with three TabPage. This example uses the AddRange method to add an array of tab pages to the tabControl1 tab control. Notice that the TabPages property gets the tabControl1 controls collection, in order to add the array of tab pages to this collection.

Use the System.Drawing and System.Windows.Forms namespaces for this collection.

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();
        this.tabPage2 = new TabPage();
        this.tabPage3 = new TabPage();

        // Gets the controls collection for tabControl1.
        // Adds an array of tab pages to this collection.
        this.tabControl1.Controls.AddRange(new TabPage[] {
            tabPage1, tabPage2, tabPage3});

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

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also