Form.MdiParent 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置此窗体的当前多文档界面 (MDI) 父窗体。
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; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form? MdiParent { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.MdiParent : System.Windows.Forms.Form with get, set
Public Property MdiParent As Form
属性值
Form,表示 MDI 父窗体。
- 属性
例外
分配给此属性的 Form 没有被标记为 MDI 容器。
示例
以下示例演示如何在 MDI 应用程序中创建子窗体。 示例代码创建一个具有唯一文本的窗体来标识子窗体。 该示例使用 MdiParent 属性指定窗体是子窗体。 此示例要求从属性设置为true的IsMdiContainer窗体中调用示例中的代码,并且该窗体具有名为 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 子窗体的属性。 可以使用 MDI 子窗体中的此属性获取所有子窗体需要或调用对所有子窗体执行操作的方法的全局信息。
备注
如果 MDI 子窗体上有两MenuStrip个控件,则父窗体的设置trueIsMdiContainer仅合并其中一个MenuStrip控件的内容。 用于 Merge 合并 MDI 父窗体上其他子 MenuStrip 控件的内容。