Control.ControlCollection Control.ControlCollection Control.ControlCollection Control.ControlCollection Class

定義

表示 Control 物件的集合。Represents a collection of Control objects.

public: ref class Control::ControlCollection : System::Windows::Forms::Layout::ArrangedElementCollection, 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
type Control.ControlCollection = class
    inherit ArrangedElementCollection
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
Public Class Control.ControlCollection
Inherits ArrangedElementCollection
Implements ICloneable, IList
繼承
Control.ControlCollectionControl.ControlCollectionControl.ControlCollectionControl.ControlCollection
衍生
屬性
實作

範例

下列程式碼範例會Control Control.ControlCollection從衍生類別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. 此範例會要求您在上建立Panel Button、和Form至少一個RadioButton控制項。The example requires that you have created a Panel, a Button, and at least one RadioButton control on a Form. 控制項會新增Panel至控制項,並將控制項加入至FormPanel RadioButtonThe RadioButton controls are added to the Panel control, and the Panel control added to the Form. 按一下按鈕時,會radioButton2 Control.ControlCollection從中移除名為的選項按鈕。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

備註

Add、和方法RemoveAt可讓您新增和移除集合中的個別控制項。 RemoveThe 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.

您可以藉由將Control控制項傳遞Contains至方法,判斷是否為集合的成員。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.

建構函式

Control.ControlCollection(Control) Control.ControlCollection(Control) Control.ControlCollection(Control) Control.ControlCollection(Control)

初始化 Control.ControlCollection 類別的新執行個體。Initializes a new instance of the Control.ControlCollection class.

屬性

Count Count Count Count

取得集合所包含的項目數目。Gets the number of elements contained in the collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得值,這個值表示此集合物件是否為唯讀。Gets a value that indicates whether this collection object is read-only.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

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

Item[String] Item[String] Item[String] Item[String]

表示集合中具有指定索引鍵的 ControlIndicates a Control with the specified key in the collection.

Owner Owner Owner Owner

取得擁有這個 Control.ControlCollection 的控制項。Gets the control that owns this Control.ControlCollection.

方法

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

將指定的控制項加入至控制項集合中。Adds the specified control to the control collection.

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

將控制項物件陣列加入至集合。Adds an array of control objects to the collection.

Clear() Clear() Clear() Clear()

移除集合中所有的控制項。Removes all controls from the collection.

Contains(Control) Contains(Control) Contains(Control) Contains(Control)

判斷指定的控制項是否為集合的成員。Determines whether the specified control is a member of the collection.

ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)

判斷 Control.ControlCollection 是否包含具有指定索引鍵的項目。Determines whether the Control.ControlCollection contains an item with the specified key.

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.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定目前的集合物件和指定的物件是否相等。Specifies whether the current collection object and the specified object are equal.

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.

GetChildIndex(Control) GetChildIndex(Control) GetChildIndex(Control) GetChildIndex(Control)

擷取控制項集合中指定之子控制項的索引。Retrieves the index of the specified child control within the control collection.

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.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

擷取用來反覆查看 Control.ControlCollection 之列舉值物件的參考。Retrieves a reference to an enumerator object that is used to iterate over a Control.ControlCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

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.

IndexOfKey(String) IndexOfKey(String) IndexOfKey(String) IndexOfKey(String)

擷取指定之項目在集合中第一次出現的索引。Retrieves the index of the first occurrence of the specified item within the collection.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

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

從控制項集合中移除指定的控制項。Removes the specified control from the control collection.

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

從控制項集合中指定的索引位置移除控制項。Removes a control from the control collection at the specified indexed location.

RemoveByKey(String) RemoveByKey(String) RemoveByKey(String) RemoveByKey(String)

移除具有指定索引鍵的子控制項。Removes the child control with the specified key.

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.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

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

如需這個成員的說明,請參閱 Clone()For a description of this member, see Clone().

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

如需這個成員的說明,請參閱 Add(Object)For a description of this member, see Add(Object).

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

如需這個成員的說明,請參閱 Contains(Object)For a description of this member, see Contains(Object).

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

如需這個成員的說明,請參閱 IndexOf(Object)For a description of this member, see IndexOf(Object).

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

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

如需這個成員的說明,請參閱 Remove(Object)For a description of this member, see Remove(Object).

擴充方法

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)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱