Freigeben über


Form.ControlCollection.Add-Methode

Fügt dem Formular ein Steuerelement hinzu.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Overrides Sub Add ( _
    value As Control _
)
'Usage
Dim instance As ControlCollection
Dim value As Control

instance.Add(value)
public override void Add (
    Control value
)
public:
virtual void Add (
    Control^ value
) override
public void Add (
    Control value
)
public override function Add (
    value : Control
)

Parameter

  • value
    Das Control, das dem Formular hinzugefügt werden soll.

Ausnahmen

Ausnahmetyp Bedingung

Exception

Einem übergeordneten MDI-Formular (Multiple Document Interface) dürfen keine Steuerelemente hinzugefügt werden.

Hinweise

Mit dieser Methode können Sie dem Formular Steuerelemente hinzufügen. Wenn Sie dem Formular eine Gruppe bereits erstellter Steuerelemente hinzufügen möchten, verwenden Sie die Control.ControlCollection.AddRange-Methode der Control.ControlCollection-Klasse.

Beispiel

Im folgenden Codebeispiel wird der Steuerelementauflistung eines Formulars ein TextBox-Steuerelement und ein Label-Steuerelement hinzugefügt. Im Beispiel ist es erforderlich, dass ein Formular mit dem Namen Form1 erstellt wurde.

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

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Form.ControlCollection-Klasse
Form.ControlCollection-Member
System.Windows.Forms-Namespace
Remove