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


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

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
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); }
public: void AddMyControls() { TextBox^ textBox1 = gcnew TextBox; Label^ label1 = gcnew Label; // Initialize the controls and their bounds. label1->Text = "First Name"; label1->Location = Point( 48, 48 ); label1->Size = System::Drawing::Size( 104, 16 ); textBox1->Text = ""; 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 ); }

System.Windows.Forms.Layout.ArrangedElementCollection
System.Windows.Forms.Control.ControlCollection
System.Windows.Forms.Form.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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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