Gets the collection of controls contained within the control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
<BrowsableAttribute(False)> _
Public ReadOnly Property Controls As Control..::..ControlCollection[BrowsableAttribute(false)]
public Control..::..ControlCollection Controls { get; }[BrowsableAttribute(false)]
public:
property Control..::..ControlCollection^ Controls {
Control..::..ControlCollection^ get ();
}[<BrowsableAttribute(false)>]
member Controls : Control..::..ControlCollection
Property Value
Type: System.Windows.FormsA Control
A Control can act as a parent to a collection of controls. For example, when several controls are added to a Form, each of the controls is a member of the Control
You can manipulate the controls in the Control
When adding several controls to a parent control, it is recommended that you call the SuspendLayout method before initializing the controls to be added. After adding the controls to the parent control, call the ResumeLayout method. Doing so will increase the performance of applications with many controls.
Use the Controls property to iterate through all controls of a form, including nested controls. Use the GetNextControl method to retrieve the previous or next child control in the tab order. Use the ActiveControl property to get or set the active control of a container control.
The following code example removes a Control from the Control
' Remove the RadioButton control if it exists.
Private Sub RemoveButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RemoveButton.Click
If Panel1.Controls.Contains(RemoveButton) Then
Panel1.Controls.Remove(RemoveButton)
End If
End Sub
// Remove the RadioButton control if it exists.
private void removeButton_Click(object sender, System.EventArgs e)
{
if(panel1.Controls.Contains(removeButton))
{
panel1.Controls.Remove(removeButton);
}
}
// Remove the RadioButton control if it exists.
private:
void removeButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
if ( panel1->Controls->Contains( removeButton ) )
{
panel1->Controls->Remove( removeButton );
}
}
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.