Freigeben über


Form.ControlCollection-Klasse

Stellt eine Auflistung von Steuerelementen im Formular dar.

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

Syntax

'Declaration
<ComVisibleAttribute(False)> _
Public Class ControlCollection
    Inherits ControlCollection
'Usage
Dim instance As ControlCollection
[ComVisibleAttribute(false)] 
public class ControlCollection : ControlCollection
[ComVisibleAttribute(false)] 
public ref class ControlCollection : public ControlCollection
/** @attribute ComVisibleAttribute(false) */ 
public class ControlCollection extends ControlCollection
ComVisibleAttribute(false) 
public class ControlCollection extends ControlCollection

Hinweise

Diese Klasse stellt die Auflistung von Steuerelementen dar, die in einem Formular enthalten sind. Verwenden Sie die Add-Methode, um dem Formular ein Steuerelement hinzuzufügen, und die Remove-Methode, um das Steuerelement aus dem Formular zu entfernen. Die Steuerelementauflistung, die durch diese Klasse dargestellt wird, kann nicht ohne Bindung an ein bestimmtes Formular erstellt werden. Daher können Sie nicht mehrere Instanzen dieser Steuerelementauflistung erstellen und diese für ein aktives Formular austauschen, um unterschiedliche Steuerelementlayouts bereitzustellen.

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

Vererbungshierarchie

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

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

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-Member
System.Windows.Forms-Namespace
Control.ControlCollection-Klasse