Form.TopMost 屬性

定義

取得或設定值,該值代表是否要將此表單顯示成最上層的表單。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 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

備註

最上層的表單會重迭所有其他(非最上層)表單,即使它不是作用中或前景形式也一樣。A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. 最上層的表單一律會顯示在桌面上視窗的迭置順序最高的位置。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.

適用於

另請參閱