Form.MdiChildren Form.MdiChildren Form.MdiChildren Form.MdiChildren Property

定义

获取窗体的数组,这些窗体表示以此窗体作为父级的多文档界面 (MDI) 子窗体。Gets an array of forms that represent the multiple-document interface (MDI) child forms that are parented to this form.

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; }
member this.MdiChildren : System.Windows.Forms.Form[]
Public ReadOnly Property MdiChildren As Form()

属性值

Form[]

Form 对象的数组,每个对象都标识此窗体的一个 MDI 子窗体。An array of Form objects, each of which identifies one of this form's MDI child forms.

示例

下面的示例演示如何使用 MdiChildren 属性来循环访问 MDI 子窗体列表,并向每个窗体添加 @no__t 控件。The following example demonstrates how to use the MdiChildren property to iterate through the list of MDI child forms and add a Button control to each.

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 子窗体的引用。This property allows you to obtain references to all the MDI child forms currently opened in an MDI parent form. 若要创建 MDI 子窗体,请将作为 MDI 父窗体的 @no__t 分配给子窗体的 @no__t 属性。To create an MDI child form, assign the Form that will be the MDI parent form to the MdiParent property of the child form.

您可以使用此属性循环遍历所有 MDI 子窗体,以执行一些操作,例如在 MDI 父窗体关闭时将数据保存到数据库,或根据在应用程序中执行的操作更新子窗体上的字段。You can use this property to loop through all the MDI child forms to perform operations such as saving data to a database when the MDI parent form closes or to update fields on the child forms based on actions performed in your application.

适用于

另请参阅