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 属性循环访问 MDI 子窗体的列表,并将控件 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

注解

此属性允许您获取对当前在 MDI 父窗体中打开的所有 MDI 子窗体的引用。 若要创建 MDI 子窗体,请将作为 MDI 父窗体的 分配给FormMdiParent子窗体的 属性。

可以使用此属性循环访问所有 MDI 子窗体,以执行诸如在 MDI 父窗体关闭时将数据保存到数据库等操作,或者根据在应用程序中执行的操作更新子窗体上的字段。

适用于

另请参阅