.ControlCollection .Add Method
.NET Framework 4.6 and 4.5
Adds the specified control to the control collection.
public virtual void Add(
Exception Condition Exception
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
method allows you to add Add objects to the end of the control collection. Control
You can also add new
objects to the collection by using the Control method. AddRange
To remove a
that you previously added, use the Control , Remove , or RemoveAt methods. Clear
can only be assigned to one Control at a time. If the Control .ControlCollection is already a child of another control it is removed from that control before it is added to another control. Control Notes to Inheritors
in a derived class, be sure to call the base class's Add method to ensure that the control is added to the collection. Add
The following code example adds a
to the Control of the derived class Control .ControlCollection . The example requires that you have created a Panel control and a Panel control on a Button . When the button is clicked, a Form control is added to the panel's TextBox . Control .ControlCollection
// Create a TextBox to add to the Panel.
private TextBox textBox1 = new TextBox();
// Add controls to the Panel using the Add method.
private void addButton_Click( object sender, System.EventArgs e)
Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client Profile
Supported in: 4, 3.5 SP1
( 1500 characters remaining)
Thank you for your feedback