Form.ControlCollection Class
Represents a collection of controls on the form.
For a list of all members of this type, see Form.ControlCollection Members.
System.Object
System.Windows.Forms.Control.ControlCollection
System.Windows.Forms.Form.ControlCollection
[Visual Basic] Public Class Form.ControlCollection Inherits Control.ControlCollection [C#] public class Form.ControlCollection : Control.ControlCollection [C++] public __gc class Form.ControlCollection : public Control.ControlCollection [JScript] public class Form.ControlCollection extends Control.ControlCollection
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
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 method 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.
Example
[Visual Basic, C#, C++] The following example adds a TextBox and Label control to the control collection of a form. The example assumes that a form has been created and named Form1.
[Visual Basic] 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 [C#] public void AddMyControls() { TextBox textBox1 = new TextBox(); Label label1 = 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); } [C++] public: void AddMyControls() { TextBox* textBox1 = new TextBox(); Label* label1 = new Label(); // Initialize the controls and their bounds. label1->Text = S"First Name"; label1->Location = Point(48,48); label1->Size = System::Drawing::Size(104, 16); textBox1->Text = S""; textBox1->Location = Point(48, 64); textBox1->Size = System::Drawing::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); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Windows.Forms
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
See Also
Form.ControlCollection Members | System.Windows.Forms Namespace | Control.ControlCollection