Form.IsMdiContainer 屬性

定義

取得或設定值,指出表單是否為多重文件介面 (MDI) 子表單的容器。

public:
 property bool IsMdiContainer { bool get(); void set(bool value); };
public bool IsMdiContainer { get; set; }
member this.IsMdiContainer : bool with get, set
Public Property IsMdiContainer As Boolean

屬性值

如果表單為 MDI 子表單的容器,則為 true,否則為 false。 預設為 false

範例

下列範例示範如何使用 IsMdiContainer 屬性,以及變更 BackColor MDI Form 的 屬性。 若要執行此範例,請將下列程式碼貼到新的表單中。


// Create a new form.
Form mdiChildForm = new Form();

private void Form1_Load(object sender, System.EventArgs e)
{

    // Set the IsMdiContainer property to true.
    IsMdiContainer = true;

    // Set the child form's MdiParent property to 
    // the current form.
    mdiChildForm.MdiParent = this;

    // Call the method that changes the background color.
    SetBackGroundColorOfMDIForm();
}

private void SetBackGroundColorOfMDIForm()
{
    foreach ( Control ctl in this.Controls )
    {
        if ((ctl) is MdiClient)

            // If the control is the correct type,
            // change the color.
        {
            ctl.BackColor = System.Drawing.Color.PaleGreen;
        }
    }
}

' Create a new form.
Dim mdiChildForm As New Form

Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    ' Set the IsMdiContainer property to true.
    IsMdiContainer = True

    ' Set the child form's MdiParent property to 
    ' the current form.
    mdiChildForm.MdiParent = Me

    'Call the method that changes the background color.
    SetBackGroundColorOfMDIForm()
End Sub

Private Sub SetBackGroundColorOfMDIForm()
    Dim ctl As Control

    ' Loop through controls,  
    ' looking for controls of MdiClient type. 
    For Each ctl In Me.Controls
        If TypeOf (ctl) Is MdiClient Then

            ' If the control is the correct type,
            ' change the color.
            ctl.BackColor = System.Drawing.Color.PaleGreen
        End If
    Next

End Sub

備註

此屬性會將表單的顯示和行為變更為 MDI 父表單。 當此屬性設定為 true 時,表單會顯示具有凸起框線的下凹工作區。 指派給父表單的所有 MDI 子表單都會在其工作區內顯示。

關閉 MDI 父表單時, Closing 所有 MDI 子表單的事件都會在引發 MDI 父表單的事件 Closing 之前引發。 此外,所有 MDI 子表單的事件都會 Closed 在引發 MDI 父表單的事件之前 Closed 引發。

注意

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

適用於

另請參閱