Form.MdiChildren Egenskap

Definition

Hämtar en matris med formulär som representerar de underordnade MDI-formulären (multiple-document interface) som är överordnade till det här formuläret.

public:
 property cli::array <System::Windows::Forms::Form ^> ^ MdiChildren { cli::array <System::Windows::Forms::Form ^> ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form[] MdiChildren { get; }
[<System.ComponentModel.Browsable(false)>]
member this.MdiChildren : System.Windows.Forms.Form[]
Public ReadOnly Property MdiChildren As Form()

Egenskapsvärde

Form[]

En matris med Form objekt som var och en identifierar ett av formulärets underordnade MDI-formulär.

Attribut

Exempel

I följande exempel visas hur du använder MdiChildren egenskapen för att iterera genom listan över underordnade MDI-formulär och lägga till en kontroll i var och en Button .

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.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 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

Kommentarer

Med den här egenskapen kan du hämta referenser till alla underordnade MDI-formulär som för närvarande öppnas i ett överordnat MDI-formulär. Om du vill skapa ett underordnat Form MDI-formulär tilldelar du det som ska vara det överordnade MDI-formuläret till MdiParent egenskapen för det underordnade formuläret.

Du kan använda den här egenskapen för att loopa igenom alla underordnade MDI-formulär för att utföra åtgärder, till exempel spara data i en databas när det överordnade MDI-formuläret stängs eller för att uppdatera fält i de underordnade formulären baserat på åtgärder som utförs i ditt program.

Gäller för

Se även