Form.MdiChildren 属性

定义

获取窗体的数组,这些窗体表示以此窗体作为父级的多文档界面 (MDI) 子窗体。

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

属性值

Form[]

Form 对象的数组,每个对象都标识此窗体的一个 MDI 子窗体。

属性

示例

以下示例演示如何使用 MdiChildren 属性循环访问 MDI 子窗体的列表,并将控件 Button 添加到每个子窗体。

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

另请参阅