Form.MdiChildren 屬性

定義

取得表單陣列,表示身為這個表單父代的多重文件介面 (MDI) 子表單。

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

屬性值

Form[]

Form 物件的陣列,每個物件會各自識別這個表單的其中一個 MDI 子表單。

屬性

範例

下列範例示範如何使用 MdiChildren 屬性逐一 Button 查看 MDI 子表單清單,並將控制項新增至每個表單。

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

備註

此屬性可讓您取得目前在 MDI 父表單中開啟之所有 MDI 子表單的參考。 若要建立 MDI 子表單,請將 MDI 父表單指派 FormMdiParent 子表單的 屬性。

您可以使用此屬性來迴圈查看所有 MDI 子表單,以執行作業,例如在 MDI 父表單關閉時將資料儲存至資料庫,或根據應用程式中執行的動作更新子表單上的欄位。

適用於

另請參閱