Form.ControlCollection Class
Represents a collection of controls on the form.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
This class represents the collection of controls contained within a form. You can use the Add method to add a control to the form and the Remove method to remove the control from the form. The control collection represented by this class cannot be created without binding it to a specific form. As a result, you cannot create multiple instances of this control collection and interchange them with an active form to provide different control layouts.
The following code example adds a TextBox and Label control to the control collection of a form. The example requires that a form has been created and named Form1.
Public Sub AddMyControls() Dim textBox1 As New TextBox() Dim label1 As New Label() ' Initialize the controls and their bounds. label1.Text = "First Name" label1.Location = New Point(48, 48) label1.Size = New Size(104, 16) textBox1.Text = "" textBox1.Location = New Point(48, 64) textBox1.Size = New Size(104, 16) ' Add the TextBox control to the form's control collection. Controls.Add(textBox1) ' Add the Label control to the form's control collection. Controls.Add(label1) End Sub 'AddMyControls
System.Windows.Forms.Layout.ArrangedElementCollection
System.Windows.Forms.Control.ControlCollection
System.Windows.Forms.Form.ControlCollection
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.