Form.MdiParent Form.MdiParent Form.MdiParent Form.MdiParent Property

定义

获取或设置此窗体的当前多文档界面 (MDI) 父窗体。Gets or sets the current multiple-document interface (MDI) parent form of this form.

public:
 property System::Windows::Forms::Form ^ MdiParent { System::Windows::Forms::Form ^ get(); void set(System::Windows::Forms::Form ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form MdiParent { get; set; }
member this.MdiParent : System.Windows.Forms.Form with get, set
Public Property MdiParent As Form

属性值

Form,表示 MDI 父窗体。A Form that represents the MDI parent form.

异常

分配给此属性的 Form 没有被标记为 MDI 容器。The Form assigned to this property is not marked as an MDI container.

- 或 --or- 分配给此属性的 Form 同时作为子 MDI 窗体和 MDI 容器窗体。The Form assigned to this property is both a child and an MDI container form.

- 或 --or- 分配给此属性的 Form 位于其他线程上。The Form assigned to this property is located on a different thread.

示例

下面的代码示例演示如何在 MDI 应用程序中创建子窗体。The following code example demonstrates how to create child forms in an MDI application. 示例代码使用唯一的文本来确定子窗体创建一个窗体。The example code creates a form with unique text to identify the child form. 该示例使用MdiParent属性来指定窗体是子窗体。The example uses the MdiParent property to specify that a form is a child form. 此示例需要在示例代码从窗体具有调用其IsMdiContainer属性设置为true和窗体具有名为的私有类级别的整型变量childCountThis example requires that the code in the example is called from a form that has its IsMdiContainer property set to true and that the form has a private class level integer variable named childCount.

private:
   void CreateMyChildForm()
   {
      // Create a new form to represent the child form.
      Form^ child = gcnew Form;

      // Increment the private child count.
      childCount++;

      // Set the text of the child form using the count of child forms.
      String^ formText = String::Format( "Child {0}", childCount );
      child->Text = formText;

      // Make the new form a child form.
      child->MdiParent = this;

      // Display the child form.
      child->Show();
   }
private void CreateMyChildForm ()
{
   // Create a new form to represent the child form.
   Form child = new Form();
   // Increment the private child count.
   childCount++;
   // Set the text of the child form using the count of child forms.
   String formText = "Child " + childCount;
   child.Text = formText;

   // Make the new form a child form.
   child.MdiParent = this;
   // Display the child form.
   child.Show();
}
Private Sub CreateMyChildForm()
   ' Create a new form to represent the child form.
   Dim child As New Form()
   ' Increment the private child count.
   childCount += 1
   ' Set the text of the child form using the count of child forms.
   Dim formText As String = "Child " + childCount.ToString()
   child.Text = formText

   ' Make the new form a child form.
   child.MdiParent = Me
   ' Display the child form.
   child.Show()
End Sub

注解

若要创建的 MDI 子窗体,将分配Form,将为到 MDI 父窗体MdiParent子窗体的属性。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 子窗体中的此属性。You can use this property from an MDI child form to obtain global information that all child forms need or to invoke methods that perform actions to all child forms.

备注

如果有两个MenuStrip上设置的 MDI 子窗体控件IsMdiContainertrue父窗体将仅其中一个的内容合并MenuStrip控件。If there are two MenuStrip controls on an MDI child form, setting IsMdiContainer to true for the parent form merges the contents of only one of the MenuStrip controls. 使用Merge合并的其他子内容MenuStripMDI 父窗体上的控件。Use Merge to merge the contents of additional child MenuStrip controls on the MDI parent form.

安全性

UIPermission
用于请求窗体。for requesting a form. 关联枚举:AllWindowsAssociated enumeration: AllWindows.

适用于

另请参阅