Control.ControlCollection クラス

Control オブジェクトのコレクションを表します。

この型のすべてのメンバの一覧については、Control.ControlCollection メンバ を参照してください。

System.Object
   System.Windows.Forms.Control.ControlCollection
      System.Windows.Forms.Form.ControlCollection
      System.Windows.Forms.TabControl.ControlCollection
      System.Windows.Forms.TabPage.TabPageControlCollection

Public Class Control.ControlCollection
   Implements IList, ICollection, IEnumerable, ICloneable
[C#]
public class Control.ControlCollection : IList, ICollection,
   IEnumerable, ICloneable
[C++]
public __gc class Control.ControlCollection : public IList,
   ICollection, IEnumerable, ICloneable
[JScript]
public class Control.ControlCollection implements IList,
   ICollection, IEnumerable, ICloneable

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

AddRemoveRemoveAt の各メソッドを使用すると、コレクションから個別のコントロールを追加および削除できます。また、 AddRange メソッドや Clear メソッドを使用して、すべてのコントロールをコレクションに追加したり、コレクションから削除したりできます。

コントロールを Contains メソッドに渡すことによって、 Control がコレクションのメンバかどうかを確認できます。コレクション内の Control の位置のインデックス値を取得するには、コントロールを IndexOf メソッドに渡します。 CopyTo メソッドを呼び出すことによって、コレクションを配列の中にコピーできます。

使用例

[Visual Basic, C#, C++] Control が派生クラス PanelControl.ControlCollection のメンバである場合に、そのコントロールをコレクションから削除する例を次に示します。この例は、 Form 上に PanelButton 、および少なくとも 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

[C#] 
// 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);
   }
}

[C++] 
// 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);
    }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

Control.ControlCollection メンバ | System.Windows.Forms 名前空間 | Control | IList