Freigeben über


Form.MdiChildren-Eigenschaft

Ruft ein Array von Formularen ab, das die untergeordneten MDI (Multiple Document Interface)-Formulare darstellt, deren übergeordnetes Formular dieses Formular ist.

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

Syntax

'Declaration
Public ReadOnly Property MdiChildren As Form()
'Usage
Dim instance As Form
Dim value As Form()

value = instance.MdiChildren
public Form[] MdiChildren { get; }
public:
property array<Form^>^ MdiChildren {
    array<Form^>^ get ();
}
/** @property */
public Form[] get_MdiChildren ()
public function get MdiChildren () : Form[]

Eigenschaftenwert

Ein Array von Form-Objekten, von denen jedes ein untergeordnetes MDI-Formular dieses Formulars bezeichnet.

Hinweise

Mit dieser Eigenschaft können Sie Verweise auf alle untergeordneten MDI-Formulare abrufen, die momentan in einem übergeordneten MDI-Formular geöffnet sind. Zum Erstellen eines untergeordneten MDI-Formulars weisen Sie der MdiParent-Eigenschaft des untergeordneten Formulars die Form zu, die als übergeordnetes MDI-Formular fungiert.

Verwenden Sie diese Eigenschaft, um alle untergeordneten MDI-Formulare in einer Schleife zu durchlaufen und Vorgänge auszuführen, z. B. das Speichern von Daten in einer Datenbank, wenn das übergeordnete MDI-Fenster geschlossen wird oder das Aktualisieren von Feldern in den untergeordneten Formularen entsprechend den in der Anwendung ausgeführten Vorgängen.

Beispiel

Im folgenden Codebeispiel wird das Durchlaufen der Liste von untergeordneten MDI-Formularen, denen jeweils ein Button-Steuerelement hinzugefügt wird, mithilfe der MdiChildren-Eigenschaft veranschaulicht.

Private Sub AddButtonsToMyChildren()
    ' If there are child forms in the parent form, add Button controls to them.
    Dim x As Integer
    For x = 0 To (Me.MdiChildren.Length) - 1
        ' Create a temporary Button control to add to the child form.
        Dim tempButton As New Button()
        ' Set the location and text of the Button control.
        tempButton.Location = New Point(10, 10)
        tempButton.Text = "OK"
        ' Create a temporary instance of a child form (Form 2 in this case).
        Dim tempChild As Form = CType(Me.MdiChildren(x), Form)
        ' Add the Button control to the control collection of the form.
        tempChild.Controls.Add(tempButton)
    Next x
End Sub 'AddButtonsToMyChildren
private void AddButtonsToMyChildren()
{
   // If there are child forms in the parent form, add Button controls to them.
   for (int x =0; x < this.MdiChildren.Length;x++)
   {
      // Create a temporary Button control to add to the child form.
      Button tempButton = new Button();
      // Set the location and text of the Button control.
      tempButton.Location = new Point(10,10);
      tempButton.Text = "OK";
      // Create a temporary instance of a child form (Form 2 in this case).
      Form tempChild = (Form)this.MdiChildren[x];
      // Add the Button control to the control collection of the form.
      tempChild.Controls.Add(tempButton);
   }
}
private:
   void AddButtonsToMyChildren()
   {
      // If there are child forms in the parent form, add Button controls to them.
      for ( int x = 0; x < this->MdiChildren->Length; x++ )
      {
         // Create a temporary Button control to add to the child form.
         Button^ tempButton = gcnew Button;

         // Set the location and text of the Button control.
         tempButton->Location = Point(10,10);
         tempButton->Text = "OK";

         // Create a temporary instance of a child form (Form 2 in this case).
         Form^ tempChild = dynamic_cast<Form^>(this->MdiChildren[ x ]);

         // Add the Button control to the control collection of the form.
         tempChild->Controls->Add( tempButton );
      }
   }
private void AddButtonsToMyChildren()
{
    // If there are child forms in the parent form, add 
    // Button controls to them.
    for (int x = 0; x < this.get_MdiChildren().length; x++)
    {
        // Create a temporary Button control to add to the child form.
        Button tempButton = new Button();

        // Set the location and text of the Button control.
        tempButton.set_Location(new Point(10, 10));
        tempButton.set_Text("OK");

        // Create a temporary instance of a child form
        //(Form 2 in this case).
        Form tempChild = (Form)(this.get_MdiChildren().get_Item(x));

        // Add the Button control to the control collection of the form.
        tempChild.get_Controls().Add(tempButton);
    }
} //AddButtonsToMyChildren

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-Klasse
Form-Member
System.Windows.Forms-Namespace
Form.IsMdiChild-Eigenschaft
Form.IsMdiContainer-Eigenschaft
MdiParent