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

屬性值

Form

Form,代表 MDI 父表單。

屬性

例外狀況

指派給這個屬性的 Form 並未標記為 MDI 容器。

-或- 指派給這個屬性的 Form 既是子表單也是 MDI 容器表單。

-或- 指派給這個屬性的 Form 位於不同的執行緒。

範例

下列範例示範如何在 MDI 應用程式中建立子表單。 範例程式碼會建立具有唯一文字的表單,以識別子表單。 此範例會 MdiParent 使用 屬性來指定表單是子表單。 此範例要求範例中的程式碼是從其 屬性設定為 trueIsMdiContainer 表單中呼叫,而且該表單具有名為 的私人 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 父表單指派 FormMdiParent 子表單的 屬性。 您可以從 MDI 子表單使用這個屬性,以取得所有子表單所需的全域資訊,或叫用對所有子表單執行動作的方法。

注意

如果 MDI 子表單上有兩 MenuStrip 個控制項,則父表單的 設定 IsMdiContainertrue 只會合並其中一個 MenuStrip 控制項的內容。 用來 Merge 合併 MDI 父表單上其他子 MenuStrip 控制項的內容。

適用於

另請參閱