Form.ControlCollection.Add メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


例外の種類 | 条件 |
---|---|
マルチ ドキュメント インターフェイス (MDI: Multiple Document Interface) 親フォームには、コントロールを追加できません。 |

このメソッドを使用して、コントロールをフォームに追加できます。既に作成されているコントロールのグループをフォームに追加する場合は、Control.ControlCollection クラスの Control.ControlCollection.AddRange メソッドを使用します。

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 ); }

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


Weblioに収録されているすべての辞書からForm.ControlCollection.Add メソッドを検索する場合は、下記のリンクをクリックしてください。

- Form.ControlCollection.Add メソッドのページへのリンク