::ControlCollection ::Add Method (Control^)
.NET Framework (current version)
Adds the specified control to the control collection.
System.Windows.Forms (in System.Windows.Forms.dll)
virtual void Add(
The specified control is a top-level control, or a circular control reference would result if this control were added to the control collection.
The object assigned to the
value parameter is not a Control.
Add method allows you to add Control objects to the end of the control collection.
You can also add new
Control objects to the collection by using the AddRange method.
To remove a
Control that you previously added, use the Remove, RemoveAt, or Clear methods.
Control can only be assigned to one Control at a time. If the ::ControlCollection Control is already a child of another control it is removed from that control before it is added to another control. Notes to Inheritors:
Add in a derived class, be sure to call the base class's Add method to ensure that the control is added to the collection.
The following code example adds a
Control to the Control of the derived class ::ControlCollection Panel. The example requires that you have created a Panel control and a Button control on a Form. When the button is clicked, a TextBox control is added to the panel's Control. ::ControlCollection
// Create a TextBox to add to the Panel.
// Add controls to the Panel using the Add method.
void addButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
textBox1 = gcnew TextBox;
panel1->Controls->Add( textBox1 );
.NET Framework Available since 1.1 Return to top