Form.MdiParent 属性

获取或设置此窗体的当前多文档界面 (MDI) 父窗体。

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

语法

声明
Public Property MdiParent As Form
用法
Dim instance As Form
Dim value As Form

value = instance.MdiParent

instance.MdiParent = value
public Form MdiParent { get; set; }
public:
property Form^ MdiParent {
    Form^ get ();
    void set (Form^ value);
}
/** @property */
public Form get_MdiParent ()

/** @property */
public void set_MdiParent (Form value)
public function get MdiParent () : Form

public function set MdiParent (value : Form)

属性值

Form,表示 MDI 父窗体。

异常

异常类型 条件

Exception

分配给此属性的 Form 没有被标记为 MDI 容器。

- 或 -

分配给此属性的 Form 同时作为子 MDI 窗体和 MDI 容器窗体。

- 或 -

分配给此属性的 Form 位于其他线程上。

备注

若要创建 MDI 子窗体,请将要成为 MDI 父窗体的 Form 分配给该子窗体的 MdiParent 属性。可以从某 MDI 子窗体使用此属性来获取所有子窗体都需要的全局信息或者调用对所有子窗体执行操作的方法。

示例

下面的代码示例演示如何在 MDI 应用程序中创建子窗体。此代码示例创建一个窗体,并用唯一的文本来标识子窗体。此示例使用 MdiParent 属性指定某个窗体为子窗体。此示例要求从一个窗体调用示例中的代码,该窗体的 IsMdiContainer 属性设置为 true,并且该窗体具有一个名为 childCount 的私有类级别的整型变量。

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
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:
   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.set_Text(formText);

    // Make the new form a child form.
    child.set_MdiParent(this);

    // Display the child form.
    child.Show();
} //CreateMyChildForm

.NET Framework 安全性

平台

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 属性
Form.MdiChildren 属性