Form.ControlCollection Form.ControlCollection Form.ControlCollection Form.ControlCollection Class

定义

表示窗体控件的集合。Represents a collection of controls on the form.

public: ref 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
Public Class Form.ControlCollection
Inherits Control.ControlCollection
继承
Form.ControlCollectionForm.ControlCollectionForm.ControlCollectionForm.ControlCollection
属性

示例

下面的代码示例将添加TextBoxLabel到窗体的控件集合的控件。The following code example adds a TextBox and Label control to the control collection of a form. 该示例需要一个窗体已创建并命名为Form1The 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 'AddMyControls

注解

此类表示窗体中包含的控件集合。This class represents the collection of controls contained within a form. 可以使用Add方法以将控件添加到窗体和Remove方法从窗体中移除控件。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.

构造函数

Form.ControlCollection(Form) Form.ControlCollection(Form) Form.ControlCollection(Form) Form.ControlCollection(Form)

初始化 Form.ControlCollection 类的新实例。Initializes a new instance of the Form.ControlCollection class.

方法

Add(Control) Add(Control) Add(Control) Add(Control)

将控件添加到窗体。Adds a control to the form.

AddRange(Control[]) AddRange(Control[]) AddRange(Control[]) AddRange(Control[])

向集合添加控制对象的数组。Adds an array of control objects to the collection.

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

从集合中移除所有控件。Removes all controls from the collection.

(Inherited from Control.ControlCollection)
Contains(Control) Contains(Control) Contains(Control) Contains(Control)

确定指定的控件是否为集合的成员。Determines whether the specified control is a member of the collection.

(Inherited from Control.ControlCollection)
ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)

确定是否Control.ControlCollection包含具有指定键的项。Determines whether the Control.ControlCollection contains an item with the specified key.

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

从特定的数组索引开始,将集合的元素复制到数组中。Copies the elements of the collection to an array, starting at a particular array index.

(Inherited from Control.ControlCollection)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定当前集合对象和所指定的对象是否相等。Specifies whether the current collection object and the specified object are equal.

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

搜索控件通过其Name属性,并生成匹配的所有控件的数组。Searches for controls by their Name property and builds an array of all the controls that match.

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

检索控件集合内指定的子控件的索引。Retrieves the index of the specified child control within the control collection.

(Inherited from Control.ControlCollection)
GetChildIndex(Control, Boolean) GetChildIndex(Control, Boolean) GetChildIndex(Control, Boolean) 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)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

检索用于循环访问的枚举器对象的引用Control.ControlCollectionRetrieves a reference to an enumerator object that is used to iterate over a Control.ControlCollection.

(Inherited from Control.ControlCollection)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Control.ControlCollection)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(Control) IndexOf(Control) IndexOf(Control) IndexOf(Control)

检索控件集合中指定的控件的索引。Retrieves the index of the specified control in the control collection.

(Inherited from Control.ControlCollection)
IndexOfKey(String) IndexOfKey(String) IndexOfKey(String) IndexOfKey(String)

检索指定项在集合中的第一个匹配项的索引。Retrieves the index of the first occurrence of the specified item within the collection.

(Inherited from Control.ControlCollection)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Control) Remove(Control) Remove(Control) Remove(Control)

从窗体中移除控件。Removes a control from the form.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

从控件集合中指定索引位置处移除控件。Removes a control from the control collection at the specified indexed location.

(Inherited from Control.ControlCollection)
RemoveByKey(String) RemoveByKey(String) RemoveByKey(String) RemoveByKey(String)

移除具有指定键的子控件。Removes the child control with the specified key.

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

设置为指定的索引值集合中的指定的子控件的索引。Sets the index of the specified child control in the collection to the specified index value.

(Inherited from Control.ControlCollection)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

属性

Count Count Count Count

获取集合中包含的元素数。Gets the number of elements contained in the collection.

(Inherited from Control.ControlCollection)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取一个值,它指示此集合对象是否是只读的。Gets a value that indicates whether this collection object is read-only.

(Inherited from Control.ControlCollection)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

指示Control指定索引处集合中的位置。Indicates the Control at the specified indexed location in the collection.

(Inherited from Control.ControlCollection)
Item[String] Item[String] Item[String] Item[String]

指示Control与集合中指定的键。Indicates a Control with the specified key in the collection.

(Inherited from Control.ControlCollection)
Owner Owner Owner Owner

获取拥有此控件Control.ControlCollectionGets the control that owns this Control.ControlCollection.

(Inherited from Control.ControlCollection)

显式界面实现

ICloneable.Clone() ICloneable.Clone() ICloneable.Clone() ICloneable.Clone()

有关此成员的说明,请参见 Clone()For a description of this member, see Clone().

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

有关此成员的说明,请参见 Add(Object)For a description of this member, see Add(Object).

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

有关此成员的说明,请参见 Contains(Object)For a description of this member, see Contains(Object).

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

有关此成员的说明,请参见 IndexOf(Object)For a description of this member, see IndexOf(Object).

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

有关此成员的说明,请参见 Insert(Int32, Object)For a description of this member, see Insert(Int32, Object).

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

有关此成员的说明,请参见 Remove(Object)For a description of this member, see Remove(Object).

(Inherited from Control.ControlCollection)

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

将转换IEnumerableIQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅