แก้ไข

แชร์ผ่าน


Form.ControlCollection Class

Definition

Represents a collection of controls on the form.

public: ref class Form::ControlCollection : System::Windows::Forms::Control::ControlCollection
public class Form.ControlCollection : System.Windows.Forms.Control.ControlCollection
[System.Runtime.InteropServices.ComVisible(false)]
public class Form.ControlCollection : System.Windows.Forms.Control.ControlCollection
type Form.ControlCollection = class
    inherit Control.ControlCollection
[<System.Runtime.InteropServices.ComVisible(false)>]
type Form.ControlCollection = class
    inherit Control.ControlCollection
Public Class Form.ControlCollection
Inherits Control.ControlCollection
Inheritance
Form.ControlCollection
Inheritance
Attributes

Examples

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:
   void AddMyControls()
   {
      TextBox^ textBox1 = gcnew TextBox;
      Label^ label1 = gcnew Label;
      
      // Initialize the controls and their bounds.
      label1->Text = "First Name";
      label1->Location = Point( 48, 48 );
      label1->Size = System::Drawing::Size( 104, 16 );
      textBox1->Text = "";
      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 );
   }
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);
 }
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

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 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.

Constructors

Form.ControlCollection(Form)

Initializes a new instance of the Form.ControlCollection class.

Properties

Count

Gets the number of elements contained in the collection.

(Inherited from Control.ControlCollection)
IsReadOnly

Gets a value that indicates whether this collection object is read-only.

(Inherited from Control.ControlCollection)
Item[Int32]

Indicates the Control at the specified indexed location in the collection.

(Inherited from Control.ControlCollection)
Item[String]

Indicates a Control with the specified key in the collection.

(Inherited from Control.ControlCollection)
Owner

Gets the control that owns this Control.ControlCollection.

(Inherited from Control.ControlCollection)

Methods

Add(Control)

Adds a control to the form.

AddRange(Control[])

Adds an array of control objects to the collection.

(Inherited from Control.ControlCollection)
Clear()

Removes all controls from the collection.

(Inherited from Control.ControlCollection)
Contains(Control)

Determines whether the specified control is a member of the collection.

(Inherited from Control.ControlCollection)
ContainsKey(String)

Determines whether the Control.ControlCollection contains an item with the specified key.

(Inherited from Control.ControlCollection)
CopyTo(Array, Int32)

Copies the elements of the collection to an array, starting at a particular array index.

(Inherited from Control.ControlCollection)
Equals(Object)

Specifies whether the current collection object and the specified object are equal.

(Inherited from Control.ControlCollection)
Find(String, Boolean)

Searches for controls by their Name property and builds an array of all the controls that match.

(Inherited from Control.ControlCollection)
GetChildIndex(Control, Boolean)

Retrieves the index of the specified child control within the control collection, and optionally raises an exception if the specified control is not within the control collection.

(Inherited from Control.ControlCollection)
GetChildIndex(Control)

Retrieves the index of the specified child control within the control collection.

(Inherited from Control.ControlCollection)
GetEnumerator()

Retrieves a reference to an enumerator object that is used to iterate over a Control.ControlCollection.

(Inherited from Control.ControlCollection)
GetHashCode()

Returns the hash code for this instance.

(Inherited from Control.ControlCollection)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(Control)

Retrieves the index of the specified control in the control collection.

(Inherited from Control.ControlCollection)
IndexOfKey(String)

Retrieves the index of the first occurrence of the specified item within the collection.

(Inherited from Control.ControlCollection)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Control)

Removes a control from the form.

RemoveAt(Int32)

Removes a control from the control collection at the specified indexed location.

(Inherited from Control.ControlCollection)
RemoveByKey(String)

Removes the child control with the specified key.

(Inherited from Control.ControlCollection)
SetChildIndex(Control, Int32)

Sets the index of the specified child control in the collection to the specified index value.

(Inherited from Control.ControlCollection)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICloneable.Clone()

This API supports the product infrastructure and is not intended to be used directly from your code.

For a description of this member, see Clone().

(Inherited from Control.ControlCollection)
ICollection.IsSynchronized

For a description of this member, see the IsSynchronized property.

(Inherited from ArrangedElementCollection)
ICollection.SyncRoot

For a description of this member, see the SyncRoot property.

(Inherited from ArrangedElementCollection)
IList.Add(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

For a description of this member, see Add(Object).

(Inherited from Control.ControlCollection)
IList.Clear()

For a description of this member, see the Clear() method.

(Inherited from ArrangedElementCollection)
IList.Contains(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

For a description of this member, see Contains(Object).

(Inherited from Control.ControlCollection)
IList.IndexOf(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

For a description of this member, see IndexOf(Object).

(Inherited from Control.ControlCollection)
IList.Insert(Int32, Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

For a description of this member, see Insert(Int32, Object).

(Inherited from Control.ControlCollection)
IList.IsFixedSize

For a description of this member, see the IsFixedSize property.

(Inherited from ArrangedElementCollection)
IList.Item[Int32]

For a description of this member, see the Item[Int32] property.

(Inherited from ArrangedElementCollection)
IList.Remove(Object)

This API supports the product infrastructure and is not intended to be used directly from your code.

For a description of this member, see Remove(Object).

(Inherited from Control.ControlCollection)
IList.RemoveAt(Int32)

For a description of this member, see the RemoveAt(Int32) method.

(Inherited from ArrangedElementCollection)

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also