Form.Modal Form.Modal Form.Modal Form.Modal Property

定义

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

public:
 property bool Modal { bool get(); };
[System.ComponentModel.Browsable(false)]
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 code 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.

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

      // 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";
	myForm.SetBounds(10,10,200,200);

	myForm.Show();
	// 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)

    myForm.Show()
    ' 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.

适用于

另请参阅