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 です。

次の例では、最上位のフォームを作成する方法を示します。 この例では、2 つのフォームを作成します。1 つは最大化され、もう 1 つは最上位のフォームとして表示されます。 という名前 bottomFormの最初のフォームは、 プロパティを WindowState 使用して最大化されて表示され、最上位のフォームの機能をよりよく示します。 という名前 topMostFormの 2 番目のフォームは、 プロパティを TopMosttrue 設定して、フォームを最上位のフォームとして表示します。 このコードを実行すると、最大化されたフォームをクリックしても、最大化されたフォームの下に最上位のフォームが表示されません。 この例では、例で定義されているメソッドを別のフォームから呼び出す必要があります。

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

注釈

最上位のフォームは、アクティブフォームまたはフォアグラウンドフォームではない場合でも、他のすべての (最上位以外の) フォームと重なるフォームです。 最上位のフォームは、常にデスクトップ上のウィンドウの z オーダーの最も高い位置に表示されます。 このプロパティを使用すると、[検索と置換] ツール ウィンドウなど、アプリケーションに常に表示されるフォームを作成できます。

適用対象

こちらもご覧ください