Control.ControlCollection 類別

定義

表示 Control 物件的集合。

public: ref class Control::ControlCollection : ICloneable, System::Collections::IList
public: ref class Control::ControlCollection : System::Windows::Forms::Layout::ArrangedElementCollection, ICloneable, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
public 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 : System.Windows.Forms.Layout.ArrangedElementCollection, ICloneable, System.Collections.IList
[<System.ComponentModel.ListBindable(false)>]
type Control.ControlCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.ComponentModel.ListBindable(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type Control.ControlCollection = class
    inherit ArrangedElementCollection
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.ComponentModel.ListBindable(false)>]
type Control.ControlCollection = class
    inherit ArrangedElementCollection
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
Public Class Control.ControlCollection
Implements ICloneable, IList
Public Class Control.ControlCollection
Inherits ArrangedElementCollection
Implements ICloneable, IList
繼承
Control.ControlCollection
繼承
Control.ControlCollection
衍生
屬性
實作

範例

如果衍生類別是集合的成員,下列程式碼範例會 ControlControl.ControlCollection 衍生類別 Panel 的 移除 。 此範例會要求您已在 上 Form 建立 、 PanelButton 和 至少一個 RadioButton 控制項。 控制項 RadioButton 會新增至 Panel 控制項,以及 Panel 加入至 的 Form 控制項。 按一下按鈕時,會從 Control.ControlCollection 中移除名為 radioButton2 的選項按鈕。

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

備註

AddRemoveRemoveAt 方法可讓您新增和移除集合中的個別控制項。 您也可以使用 AddRangeClear 方法來新增或移除集合中的所有控制項。

您可以將 控制項傳遞至 Contains 方法,以判斷 Control 是否為集合的成員。 若要取得集合中 位置的 Control 索引值,請將 控制項傳遞至 IndexOf 方法。 您可以藉由呼叫 CopyTo 方法,將集合複製到陣列中。

建構函式

Control.ControlCollection(Control)

初始化 Control.ControlCollection 類別的新執行個體。

屬性

Count

取得集合所包含的項目數目。

Count

取得集合中的項目數。

(繼承來源 ArrangedElementCollection)
IsReadOnly

取得值,這個值表示此集合物件是否為唯讀。

IsReadOnly

取得值,表示集合是否為唯讀。

(繼承來源 ArrangedElementCollection)
Item[Int32]

指示集合中指定索引位置的 Control

Item[String]

表示集合中具有指定索引鍵的 Control

Owner

取得擁有這個 Control.ControlCollection 的控制項。

方法

Add(Control)

將指定的控制項加入至控制項集合中。

AddRange(Control[])

將控制項物件陣列加入至集合。

Clear()

移除集合中所有的控制項。

Contains(Control)

判斷指定的控制項是否為集合的成員。

ContainsKey(String)

判斷 Control.ControlCollection 是否包含具有指定索引鍵的項目。

CopyTo(Array, Int32)

從特定的陣列索引開始,將集合的項目複製到陣列。

CopyTo(Array, Int32)

從目標陣列的指定之索引處開始,將這個集合的整個內容複製到相容的一維 Array

(繼承來源 ArrangedElementCollection)
Equals(Object)

指定目前的集合物件和指定的物件是否相等。

Equals(Object)

判斷兩個 ArrangedElementCollection 執行個體是否相等。

(繼承來源 ArrangedElementCollection)
Find(String, Boolean)

根據 Name 屬性搜尋控制項,並建置所有相符之控制項的陣列。

GetChildIndex(Control)

擷取控制項集合中指定之子控制項的索引。

GetChildIndex(Control, Boolean)

擷取控制項集合中指定之子控制項的索引。如果指定的控制項不在控制項集合中,則選擇性引發例外狀況。

GetEnumerator()

擷取用來反覆查看 Control.ControlCollection 之列舉值物件的參考。

GetHashCode()

傳回這個執行個體的雜湊碼。

GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 ArrangedElementCollection)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IndexOf(Control)

擷取控制項集合中指定之控制項的索引。

IndexOfKey(String)

擷取指定之項目在集合中第一次出現的索引。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Remove(Control)

從控制項集合中移除指定的控制項。

RemoveAt(Int32)

從控制項集合中指定的索引位置移除控制項。

RemoveByKey(String)

移除具有指定索引鍵的子控制項。

SetChildIndex(Control, Int32)

將集合中指定之子控制項的索引,設定為指定的索引值。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

ICloneable.Clone()

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

如需這個成員的說明,請參閱 Clone()

ICollection.IsSynchronized

如需這個成員的描述,請參閱 IsSynchronized 屬性。

(繼承來源 ArrangedElementCollection)
ICollection.SyncRoot

如需這個成員的描述,請參閱 SyncRoot 屬性。

(繼承來源 ArrangedElementCollection)
IList.Add(Object)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

如需這個成員的說明,請參閱 Add(Object)

IList.Clear()

如需這個成員的描述,請參閱 Clear() 方法。

(繼承來源 ArrangedElementCollection)
IList.Contains(Object)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

如需這個成員的說明,請參閱 Contains(Object)

IList.Contains(Object)

如需這個成員的描述,請參閱 Contains(Object) 方法。

(繼承來源 ArrangedElementCollection)
IList.IndexOf(Object)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

如需這個成員的說明,請參閱 IndexOf(Object)

IList.IndexOf(Object)

如需這個成員的描述,請參閱 IndexOf(Object) 方法。

(繼承來源 ArrangedElementCollection)
IList.Insert(Int32, Object)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

如需這個成員的說明,請參閱 Insert(Int32, Object)

IList.Insert(Int32, Object)

如需這個成員的描述,請參閱 Insert(Int32, Object) 方法。

(繼承來源 ArrangedElementCollection)
IList.IsFixedSize

如需這個成員的描述,請參閱 IsFixedSize 屬性。

(繼承來源 ArrangedElementCollection)
IList.Item[Int32]

如需這個成員的描述,請參閱 Item[Int32] 屬性。

(繼承來源 ArrangedElementCollection)
IList.Remove(Object)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

如需這個成員的說明,請參閱 Remove(Object)

IList.RemoveAt(Int32)

如需這個成員的描述,請參閱 RemoveAt(Int32) 方法。

(繼承來源 ArrangedElementCollection)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱