Form.ControlCollection.Add(Control) Form.ControlCollection.Add(Control) Form.ControlCollection.Add(Control) Form.ControlCollection.Add(Control) Method

Definition

Fügt dem Formular ein Steuerelement hinzu.Adds a control to the form.

public:
 override void Add(System::Windows::Forms::Control ^ value);
public override void Add (System.Windows.Forms.Control value);
override this.Add : System.Windows.Forms.Control -> unit
Public Overrides Sub Add (value As Control)

Parameter

value
Control Control Control Control

Das Control, das dem Formular hinzugefügt werden soll.The Control to add to the form.

Ausnahmen

Einem übergeordneten MDI-Formular (Multiple Document Interface) dürfen keine Steuerelemente hinzugefügt werden.A multiple document interface (MDI) parent form cannot have controls added to it.

Beispiele

Im folgenden Codebeispiel wird der TextBox Steuer Label Element Auflistung eines Formulars ein-Steuerelement und ein-Steuerelement hinzugefügt.The following code example adds a TextBox and Label control to the control collection of a form. Für das Beispiel muss ein Formular erstellt und benannt Form1werden.The example requires that a form has been created and named Form1.

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

Hinweise

Mit dieser Methode können Sie dem Formular Steuerelemente hinzufügen.You can use this method to add controls to the form. Wenn Sie dem Formular eine Gruppe bereits erstellter Steuerelemente hinzufügen möchten, verwenden Sie Control.ControlCollection.AddRange die-Methode Control.ControlCollection der-Klasse.If you want to add a group of already created controls to the form, use the Control.ControlCollection.AddRange method of the Control.ControlCollection class.

Gilt für:

Siehe auch