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 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. 此示例要求将示例中的代码从其 @no__t 0 属性设置为 @no__t 的窗体中调用,并且该窗体具有名为 childCount 的私有类级别整数变量。This 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 子窗体,请将作为 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 子窗体使用此属性来获取所有子窗体所需的全局信息,或调用对所有子窗体执行操作的方法。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.

备注

如果在 MDI 子窗体上有两个 @no__t 0 的控件,则将 @no__t 设置为父窗体 true 将只合并某个 @no__t 控件的内容。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. 使用 @no__t 在 MDI 父窗体上合并其他子 @no__t 控件的内容。Use Merge to merge the contents of additional child MenuStrip controls on the MDI parent form.

安全性

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

适用于

另请参阅