Form.TopLevel Form.TopLevel Form.TopLevel Form.TopLevel Property

定义

获取或设置一个值,该值指示是否将窗体显示为顶层窗口。Gets or sets a value indicating whether to display the form as a top-level window.

public:
 property bool TopLevel { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool TopLevel { get; set; }
member this.TopLevel : bool with get, set
Public Property TopLevel As Boolean

属性值

如果为 true,则将窗体显示为顶级窗口;否则,为 falsetrue to display the form as a top-level window; otherwise, false. 默认值为 trueThe default is true.

异常

多文档界面 (MDI) 父窗体必须是顶级窗口。A Multiple-document interface (MDI) parent form must be a top-level window.

示例

下面的代码示例使用Modal属性来确定是否窗体显示为模式窗体。The following code example use 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 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

注解

顶级窗体是对没有父窗体中,或者其父窗体是在桌面窗口的窗口。A top-level form is a window that has no parent form, or whose parent form is the desktop window. 顶级窗口通常用作应用程序中的主窗体。Top-level windows are typically used as the main form in an application.

适用于

另请参阅