Form.MdiChildren 属性

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public ReadOnly Property MdiChildren As Form()
用法
Dim instance As Form
Dim value As Form()

value = instance.MdiChildren
public Form[] MdiChildren { get; }
public:
property array<Form^>^ MdiChildren {
    array<Form^>^ get ();
}
/** @property */
public Form[] get_MdiChildren ()
public function get MdiChildren () : Form[]

属性值

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

备注

此属性使您得以获取对当前在某 MDI 父窗体中打开的所有 MDI 子窗体的引用。若要创建 MDI 子窗体,请将要成为 MDI 父窗体的 Form 分配给该子窗体的 MdiParent 属性。

可以使用此属性依次通过所有 MDI 子窗体,以执行一些操作,如当 MDI 父窗体关闭时将数据保存到数据库中,或者根据应用程序中执行的操作更新子窗体上的字段。

示例

下面的代码示例演示如何使用 MdiChildren 属性循环访问 MDI 子窗体的列表并向每个子窗体添加 Button 控件。

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 'AddButtonsToMyChildren
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:
   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.get_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.set_Location(new Point(10, 10));
        tempButton.set_Text("OK");

        // Create a temporary instance of a child form
        //(Form 2 in this case).
        Form tempChild = (Form)(this.get_MdiChildren().get_Item(x));

        // Add the Button control to the control collection of the form.
        tempChild.get_Controls().Add(tempButton);
    }
} //AddButtonsToMyChildren

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Form 类
Form 成员
System.Windows.Forms 命名空间
Form.IsMdiChild 属性
Form.IsMdiContainer 属性
MdiParent