TabPage::TabPageControlCollection::Add Method (Control^)

 

Adds a control to the collection.

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

public:
virtual void Add(
	Control^ value
) override

Parameters

value
Type: System.Windows.Forms::Control^

The control to add.

Exception Condition
ArgumentException

The specified control is a TabPage.

The specified control is added to the end of the collection. If the control is already a child of another control, it is removed from the other control.

The following code example creates a TabControl with one TabPage. This example uses the Add method to add a single control, button1, to the tabPage1. The Controls property is used to get the tabPage1 controls collection to add controls to the collection.

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

using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public Form
{
private:
   TabControl^ tabControl1;
   TabPage^ tabPage1;
   Button^ button1;

public:
   Form1()
   {
      this->tabControl1 = gcnew TabControl;
      this->tabPage1 = gcnew TabPage;
      this->button1 = gcnew Button;
      this->tabControl1->TabPages->Add( tabPage1 );
      this->tabControl1->Location = Point(25,25);
      this->tabControl1->Size = System::Drawing::Size( 250, 250 );

      // Gets the controls collection for tabPage1.
      // Adds button1 to this collection.
      this->tabPage1->Controls->Add( button1 );
      this->button1->Text = "button1";
      this->button1->Location = Point(25,25);
      this->ClientSize = System::Drawing::Size( 300, 300 );
      this->Controls->Add( tabControl1 );
   }

};

int main()
{
   Application::Run( gcnew Form1 );
}

.NET Framework
Available since 1.1
Return to top
Show: