Form.Modal 属性


获取一个值,该值指示是否有模式地显示此窗体。Gets a value indicating whether this form is displayed modally.

 property bool Modal { bool get(); };
public bool Modal { get; }
member this.Modal : bool
Public ReadOnly Property Modal As Boolean


如果该窗体进行模式显示,则为 true;否则为 falsetrue if the form is displayed modally; otherwise, false.



下面的示例使用 Modal 属性来确定窗体是否显示为模式窗体。The following example uses the Modal property to determine if a form is displayed as a modal form. 如果不是 FormBorderStyleTopLevel 属性将更改,以使窗体成为具有工具窗口边框的非顶级窗体。If it is not the FormBorderStyle and TopLevel properties are changed to make the form a non-top-level form with a tool window border.

   void ShowMyNonModalForm()
      Form^ myForm = gcnew Form;
      myForm->Text = "My Form";
      myForm->SetBounds( 10, 10, 200, 200 );

      // Determine if the form is modal.
      if ( myForm->Modal == false )
         // Change borderstyle and make it not a top level window.
         myForm->FormBorderStyle = ::FormBorderStyle::FixedToolWindow;
         myForm->TopLevel = false;
private void ShowMyNonModalForm()
    Form myForm = new Form();
    myForm.Text = "My Form";

    // Determine if the form is modal.
    if(myForm.Modal == false)
        // Change borderstyle and make it not a top level window.
        myForm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
        myForm.TopLevel = false;
Private Sub ShowMyNonModalForm()
    Dim myForm As New Form()
    myForm.Text = "My Form"
    myForm.SetBounds(10, 10, 200, 200)

    ' Determine if the form is modal.
    If myForm.Modal = False Then
        ' Change borderstyle and make it not a top level window.
        myForm.FormBorderStyle = FormBorderStyle.FixedToolWindow
        myForm.TopLevel = False
    End If
End Sub


当窗体以模式模式显示时,除了模式窗体上的对象之外,不会出现任何输入(键盘或鼠标单击)。When a form is displayed modally, no input (keyboard or mouse click) can occur except to objects on the modal form. 在输入到另一种形式之前,程序必须隐藏或关闭模式窗体(通常响应某些用户操作)。The program must hide or close a modal form (usually in response to some user action) before input to another form can occur. 在应用程序中,按模式显示的窗体通常用作对话框。Forms that are displayed modally are typically used as dialog boxes in an application.

您可以使用此属性来确定是否已按模式显示从方法或属性获取的窗体。You can use this property to determine whether a form that you have obtained from a method or property has been displayed modally.

若要以模式方式显示窗体,请使用 ShowDialog 方法。To display a form modally use the ShowDialog method.