Form.MdiChildren Właściwość

Definicja

Pobiera tablicę formularzy reprezentujących formularze podrzędne interfejsu wielodokumentowego (MDI), które są nadrzędne dla tego formularza.

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()

Wartość właściwości

Form[]

Tablica Form obiektów, z których każda identyfikuje jeden z formularzy podrzędnych MDI tego formularza.

Atrybuty

Przykłady

W poniższym przykładzie pokazano, jak używać MdiChildren właściwości do iterowania za pomocą listy formularzy podrzędnych MDI i dodawania Button kontrolki do każdego z nich.

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

Uwagi

Ta właściwość umożliwia uzyskanie odwołań do wszystkich formularzy podrzędnych MDI, które są obecnie otwierane w formularzu nadrzędnym MDI. Aby utworzyć formularz podrzędny MDI, przypisz Form formularz nadrzędny MDI do MdiParent właściwości formularza podrzędnego.

Tej właściwości można użyć do pętli wszystkich formularzy podrzędnych MDI w celu wykonywania operacji, takich jak zapisywanie danych w bazie danych, gdy formularz nadrzędny MDI zamyka lub aktualizuje pola na formularzach podrzędnych na podstawie akcji wykonywanych w aplikacji.

Dotyczy

Zobacz też