Form.TopMost 屬性

定義

取得或設定值,該值代表是否要將此表單顯示成最上層的表單。

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 表示要將該表單顯示為最上層的表單,否則為 false。 預設為 false

範例

下列範例示範如何建立最上層表單。 此範例會建立兩個表單,一個是最大化的,另一個表單會顯示為最上層表單。 名為 的第一個 bottomForm 表單會使用 WindowState 屬性來顯示最大化,以更能示範最上層表單的能力。 名為 的第二個 topMostForm 表單會將 TopMost 屬性 true 設定為 ,以將表單顯示為最上層表單。 執行此程式碼時,按一下最大化的表單並不會使最上層表單顯示在最大化表單下方。 此範例需要從另一個表單呼叫範例中定義的 方法。

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

備註

最上層表單是一種表單,會與所有其他 (非最上層) 表單重迭,即使表單不是使用中或前景表單也一樣。 最上層表單一律會以桌面視窗的迭置順序顯示在最高點。 您可以使用此屬性來建立一律顯示在應用程式中的表單,例如 [尋找和取代] 工具視窗。

適用於

另請參閱