Control.ControlCollection クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

<ComVisibleAttribute(False)> _ Public Class ControlCollection Inherits ArrangedElementCollection Implements IList, ICollection, IEnumerable, ICloneable
[ComVisibleAttribute(false)] public class ControlCollection : ArrangedElementCollection, IList, ICollection, IEnumerable, ICloneable
[ComVisibleAttribute(false)] public ref class ControlCollection : public ArrangedElementCollection, IList, ICollection, IEnumerable, ICloneable

Add、Remove、RemoveAt の各メソッドを使用すると、コレクションから個別のコントロールを追加および削除できます。また、AddRange メソッドや Clear メソッドを使用して、すべてのコントロールをコレクションに追加したり、コレクションから削除したりできます。
コントロールを Contains メソッドに渡すことによって、Control がコレクションのメンバかどうかを確認できます。コレクション内の Control の位置のインデックス値を取得するには、コントロールを IndexOf メソッドに渡します。CopyTo メソッドを呼び出すことによって、コレクションを配列の中にコピーできます。

Control が派生クラス Panel の Control.ControlCollection のメンバである場合に、そのコントロールをコレクションから削除するコード例を次に示します。この例では、Form 上に Panel、Button、および少なくとも 1 つの RadioButton コントロールが作成されている必要があります。RadioButton コントロールは Panel コントロールに追加され、Panel コントロールは Form コントロールに追加されます。ボタンがクリックされると、radioButton2 という名前のオプション ボタンが Control.ControlCollection から削除されます。
' 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(RadioAddRangeButton) Then Panel1.Controls.Remove(RadioAddRangeButton) End If End Sub
// 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); } }

System.Windows.Forms.Layout.ArrangedElementCollection
System.Windows.Forms.Control.ControlCollection
派生クラス


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Control.ControlCollection クラスのページへのリンク