共用方式為


Form.MdiParent 屬性

定義

取得或設定此表單的當前多文件介面(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

屬性值

A Form 代表 MDI 父表。

屬性

例外狀況

分配到此物業的容器 Form 並未被標記為 MDI 容器。

-或-

分配到此物業的同時 Form 是子物件和 MDI 容器表單。

-或-

分配到這個屬性的設定 Form 則位於另一個執行緒中。

範例

以下範例示範如何在 MDI 應用程式中建立子表單。 範例程式碼會建立一個帶有獨特文字的表單,以識別子表單。 範例中使用 該 MdiParent 特性來指定表單是子表單。 此範例要求範例中的程式碼必須從一個屬性設定 IsMdiContainer 為 的 true 表單中呼叫,且該表單有一個私有類別層級整數變數,名為 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 子表單,將 that 將是 MDI 父表單的 指派 FormMdiParent 子表單的屬性。 你可以利用 MDI 子表單的這個屬性,取得所有子表單所需的全域資訊,或呼叫執行所有子表單動作的方法。

備註

若 MDI 子表單有兩個 MenuStrip 控制項,將父表單設 IsMdiContainer 為 時 true ,僅合併其中一個 MenuStrip 控制項的內容。 用於 Merge 合併 MDI 父表單中其他子 MenuStrip 控制項的內容。

適用於

另請參閱