Form.MdiChildren 屬性

定義

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

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form[] MdiChildren { get; }

屬性值

Form[]

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

屬性

範例

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

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

備註

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

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱