Form.TopMost Form.TopMost Form.TopMost Form.TopMost Property

定义

获取或设置一个值,指示该窗体是否应显示为最顶层窗体。Gets or sets a value indicating whether the form should be displayed as a topmost form.

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

属性值

如果将窗体显示为最顶层窗体,则为 true;否则为 falsetrue to display the form as a topmost form; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例演示如何创建最顶层窗体。The following code example demonstrates how to create a topmost form. 该示例创建两个窗体,一个处于最大化,一个将显示为最顶层窗体。The example creates two forms, one that is maximized and one that will be displayed as a topmost form. 第一个窗体,名为bottomForm,将显示最大化,请使用WindowState属性,以更好地演示的最顶层窗体的能力。The first form, named bottomForm, is displayed maximized, using the WindowState property, to better demonstrate the abilities of the topmost form. 第二个名为的窗体topMostForm,设置TopMost属性设置为true窗体显示为最顶层窗体。The second form, named topMostForm, sets the TopMost property to true to display the form as a topmost form. 运行此代码时,单击最大化窗体上不会导致最顶层的窗体最大化窗体下显示。When this code is run, clicking on the maximized form will not cause the topmost form to be displayed below the maximized form. 该示例需要在示例中定义的方法称为从另一种形式。The example requires that the method defined in the example is called from another form.

private:
   void CreateMyTopMostForm()
   {
      // Create lower form to display.
      Form^ bottomForm = gcnew Form;

      // Display the lower form Maximized to demonstrate effect of TopMost property.
      bottomForm->WindowState = FormWindowState::Maximized;

      // Display the bottom form.
      bottomForm->Show();

      // Create the top most form.
      Form^ topMostForm = gcnew Form;

      // Set the size of the form larger than the default size.
      topMostForm->Size = System::Drawing::Size( 300, 300 );

      // Set the position of the top most form to center of screen.
      topMostForm->StartPosition = FormStartPosition::CenterScreen;

      // Display the form as top most form.
      topMostForm->TopMost = true;
      topMostForm->Show();
   }
private void CreateMyTopMostForm()
{
   // Create lower form to display.
   Form bottomForm = new Form();
   // Display the lower form Maximized to demonstrate effect of TopMost property.
   bottomForm.WindowState = FormWindowState.Maximized;
   // Display the bottom form.
   bottomForm.Show();
   // Create the top most form.
   Form topMostForm = new Form();
   // Set the size of the form larger than the default size.
   topMostForm.Size = new Size(300,300);
   // Set the position of the top most form to center of screen.
   topMostForm.StartPosition = FormStartPosition.CenterScreen;
   // Display the form as top most form.
   topMostForm.TopMost = true;
   topMostForm.Show();
}
Private Sub CreateMyTopMostForm()
   ' Create lower form to display.
   Dim bottomForm As New Form()
   ' Display the lower form Maximized to demonstrate effect of TopMost property.
   bottomForm.WindowState = FormWindowState.Maximized
   ' Display the bottom form.
   bottomForm.Show()
   ' Create the top most form.
   Dim topMostForm As New Form()
   ' Set the size of the form larger than the default size.
   topMostForm.Size = New Size(300, 300)
   ' Set the position of the top most form to center of screen.
   topMostForm.StartPosition = FormStartPosition.CenterScreen
   ' Display the form as top most form.
   topMostForm.TopMost = True
   topMostForm.Show()
End Sub 'CreateMyTopMostForm

注解

最顶层窗体是重叠的所有其他 (非最顶端) 窗体,即使它不处于活动状态或前景窗体的窗体。A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. 最顶层窗体始终显示在桌面上窗口的 z 顺序中最高数据点。Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop. 此属性可用于创建始终在应用程序,如查找和替换工具窗口中显示的窗体。You can use this property to create a form that is always displayed in your application, such as a Find and Replace tool window.

适用于

另请参阅