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

MDI 親フォームを表す Form

属性

例外

このプロパティに割り当てられた Form が MDI コンテナーとしてマークされていません。

  • または - このプロパティに割り当てられた Form が子フォームと MDI コンテナー フォームの両方を表しています。

  • または - このプロパティに割り当てられた Form が別のスレッドにあります。

次の例では、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 子フォームを作成するには、MDI 親フォームになるフォームを子フォームのプロパティにMdiParent割り当てますForm。 MDI 子フォームからこのプロパティを使用すると、すべての子フォームに必要なグローバル情報を取得したり、すべての子フォームに対してアクションを実行するメソッドを呼び出したりすることができます。

注意

MDI 子フォームに 2 つの MenuStrip コントロールがある場合、親フォームに設定 IsMdiContainer すると true 、コントロールの 1 つだけの内容が MenuStrip マージされます。 MDI 親フォームの追加の子MenuStripコントロールの内容をマージするために使用Mergeします。

適用対象

こちらもご覧ください