次の方法で共有


Form.ControlCollection クラス

フォーム上のコントロールのコレクションを表します。

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

System.Object
   System.Windows.Forms.Control.ControlCollection
      System.Windows.Forms.Form.ControlCollection

Public Class Form.ControlCollection
   Inherits Control.ControlCollection
[C#]
public class Form.ControlCollection : Control.ControlCollection
[C++]
public __gc class Form.ControlCollection : public
   Control.ControlCollection
[JScript]
public class Form.ControlCollection extends
   Control.ControlCollection

スレッドセーフ

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

解説

このクラスは、フォームに配置されているコントロールのコレクションを表します。フォームにコントロールを追加するには Add メソッドを使用し、フォームからコントロールを削除するには Remove メソッドを使用します。このクラスによって表されるコントロール コレクションを作成するには、そのコレクションを特定のフォームに関連付ける必要があります。このため、このコントロール コレクションの複数のインスタンスを作成し、アクティブなフォームをこれらのインスタンスで置き換えることによってコントロールを異なるレイアウトで配置することはできません。

使用例

[Visual Basic, C#, C++] TextBox コントロールと Label コントロールをフォームのコントロール コレクションに追加する例を次に示します。この例は、フォームが Form1 という名前で作成されていることを前提にしています。

 
Public Sub AddMyControls()
    Dim textBox1 As New TextBox()
    Dim label1 As New Label()
    
    ' Initialize the controls and their bounds.
    label1.Text = "First Name"
    label1.Location = New Point(48, 48)
    label1.Size = New Size(104, 16)
    textBox1.Text = ""
    textBox1.Location = New Point(48, 64)
    textBox1.Size = New Size(104, 16)
    
    ' Add the TextBox control to the form's control collection.
    Controls.Add(textBox1)
    ' Add the Label control to the form's control collection.
    Controls.Add(label1)
End Sub 'AddMyControls

[C#] 
public void AddMyControls()
 {
    TextBox textBox1 = new TextBox();
    Label label1 = new Label();
    
    // Initialize the controls and their bounds.
    label1.Text = "First Name";
    label1.Location = new Point(48,48);
    label1.Size = new Size (104, 16);
    textBox1.Text = "";
    textBox1.Location = new Point(48, 64);
    textBox1.Size = new Size(104,16);
 
    // Add the TextBox control to the form's control collection.
    Controls.Add(textBox1);
    // Add the Label control to the form's control collection.
    Controls.Add(label1);
 }
 

[C++] 
public:
void AddMyControls()
 {
    TextBox* textBox1 = new TextBox();
    Label* label1 = new Label();
    
    // Initialize the controls and their bounds.
    label1->Text = S"First Name";
    label1->Location = Point(48,48);
    label1->Size = System::Drawing::Size(104, 16);
    textBox1->Text = S"";
    textBox1->Location = Point(48, 64);
    textBox1->Size = System::Drawing::Size(104,16);
 
    // Add the TextBox control to the form's control collection.
    Controls->Add(textBox1);
    // Add the Label control to the form's control collection.
    Controls->Add(label1);
 }
 

[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 ファミリ

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

参照

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