Control.ControlCollection Class

Definition

表示 Control 对象集合。Represents a collection of Control objects.

public: ref class Control::ControlCollection : System::Windows::Forms::Layout::ArrangedElementCollection, ICloneable, System::Collections::IList
public: ref class Control::ControlCollection : ICloneable, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public class Control.ControlCollection : System.Windows.Forms.Layout.ArrangedElementCollection, ICloneable, System.Collections.IList
[System.ComponentModel.ListBindable(false)]
public class Control.ControlCollection : ICloneable, System.Collections.IList
type Control.ControlCollection = class
    inherit ArrangedElementCollection
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
type Control.ControlCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
Public Class Control.ControlCollection
Inherits ArrangedElementCollection
Implements ICloneable, IList
Public Class Control.ControlCollection
Implements ICloneable, IList
Inheritance
Control.ControlCollection
Inheritance
Control.ControlCollection
Derived
Attributes
Implements

Examples

下面的代码示例从派生类的 Control.ControlCollection 中移除 Control Panel 如果它是集合的成员。The following code example removes a Control from the Control.ControlCollection of the derived class Panel if it is a member of the collection. 该示例要求您已在 Form上创建了一个 Panel、一个 Button和至少一个 RadioButton 控件。The example requires that you have created a Panel, a Button, and at least one RadioButton control on a Form. RadioButton 控件将添加到 Panel 控件,并添加到 Form中的 Panel 控件。The RadioButton controls are added to the Panel control, and the Panel control added to the Form. 单击该按钮时,将从 Control.ControlCollection中删除名为 radioButton2 的单选按钮。When the button is clicked, the radio button named radioButton2 is removed from the Control.ControlCollection.

   // 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);
   }
}
' 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

Remarks

使用 AddRemoveRemoveAt 方法,您可以在集合中添加和移除单个控件。The Add, Remove, and RemoveAt methods enable you to add and remove individual controls from the collection. 你还可以使用 AddRangeClear 方法在集合中添加或移除所有控件。You can also use the AddRange or Clear methods to add or remove all the controls from the collection.

可以通过将控件传递到 Contains 方法来确定 Control 是否是集合的成员。You can determine if a Control is a member of the collection by passing the control into the Contains method. 若要获取集合中 Control 位置的索引值,请将该控件传递到 IndexOf 方法中。To get the index value of the location of a Control in the collection, pass the control into the IndexOf method. 可以通过调用 CopyTo 方法将集合复制到数组中。The collection can be copied into an array by calling the CopyTo method.

Constructors

Control.ControlCollection(Control)

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

Properties

Count

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

Count

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

(Inherited from ArrangedElementCollection)
IsReadOnly

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

IsReadOnly

获取一个值,该值指示集合是否是只读的。Gets a value indicating whether the collection is read-only.

(Inherited from ArrangedElementCollection)
Item[Int32]

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

Item[String]

指示集合中具有指定键的一个 ControlIndicates a Control with the specified key in the collection.

Owner

获取拥有此 Control.ControlCollection 的控件。Gets the control that owns this Control.ControlCollection.

Methods

Add(Control)

将指定的控件添加到控件集合中。Adds the specified control to the control collection.

AddRange(Control[])

将控件对象数组添加到集合中。Adds an array of control objects to the collection.

Clear()

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

Contains(Control)

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

ContainsKey(String)

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

CopyTo(Array, Int32)

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

CopyTo(Array, Int32)

从目标数组的指定索引处开始将此集合的全部内容复制到兼容的一维 ArrayCopies the entire contents of this collection to a compatible one-dimensional Array, starting at the specified index of the target array.

(Inherited from ArrangedElementCollection)
Equals(Object)

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

Equals(Object)

确定两个 ArrangedElementCollection 实例是否相等。Determines whether two ArrangedElementCollection instances are equal.

(Inherited from ArrangedElementCollection)
Find(String, Boolean)

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

GetChildIndex(Control)

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

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.

GetEnumerator()

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

GetHashCode()

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

GetHashCode()

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

(Inherited from ArrangedElementCollection)
GetType()

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

(Inherited from Object)
IndexOf(Control)

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

IndexOfKey(String)

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

MemberwiseClone()

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

(Inherited from Object)
Remove(Control)

从控件集合中移除指定的控件。Removes the specified control from the control collection.

RemoveAt(Int32)

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

RemoveByKey(String)

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

SetChildIndex(Control, Int32)

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

ToString()

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

(Inherited from Object)

Explicit Interface Implementations

ICloneable.Clone()

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

ICollection.IsSynchronized

有关此成员的说明,请参见 IsSynchronized 属性。For a description of this member, see the IsSynchronized property.

(Inherited from ArrangedElementCollection)
ICollection.SyncRoot

有关此成员的说明,请参见 SyncRoot 属性。For a description of this member, see the SyncRoot property.

(Inherited from ArrangedElementCollection)
IList.Add(Object)

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

IList.Clear()

有关此成员的说明,请参见 Clear() 方法。For a description of this member, see the Clear() method.

(Inherited from ArrangedElementCollection)
IList.Contains(Object)

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

IList.Contains(Object)

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

(Inherited from ArrangedElementCollection)
IList.IndexOf(Object)

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

IList.IndexOf(Object)

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

(Inherited from ArrangedElementCollection)
IList.Insert(Int32, Object)

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

IList.Insert(Int32, Object)

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

(Inherited from ArrangedElementCollection)
IList.IsFixedSize

有关此成员的说明,请参见 IsFixedSize 属性。For a description of this member, see the IsFixedSize property.

(Inherited from ArrangedElementCollection)
IList.Item[Int32]

有关此成员的说明,请参见 Item[Int32] 属性。For a description of this member, see the Item[Int32] property.

(Inherited from ArrangedElementCollection)
IList.Remove(Object)

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

IList.RemoveAt(Int32)

有关此成员的说明,请参见 RemoveAt(Int32) 方法。For a description of this member, see the RemoveAt(Int32) method.

(Inherited from ArrangedElementCollection)

Extension Methods

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Applies to

See also