Form.TopMost プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

/** @property */ public boolean get_TopMost () /** @property */ public void set_TopMost (boolean value)
フォームを最上位フォームとして表示する場合は true。それ以外の場合は false。既定値は false です。

最上位フォームとは、アクティブでない場合や前面のフォームではない場合でも、他のすべての (最上位でない) フォームの上に表示されるフォームのことです。最上位フォームは、常にデスクトップ ウィンドウの Z オーダーの最上位に表示されます。このプロパティを使用すると、検索/置換ウィンドウなど、アプリケーションに常に表示されるフォームを作成できます。

最上位フォームを作成するコード例を次に示します。この例では、最大化表示されたフォームと最上位フォームの 2 つのフォームを作成します。最初のフォーム bottomForm は、WindowState プロパティによって最大化表示されています。これにより、最上位フォームの動作がわかりやすくなります。2 番目のフォーム topMostForm は、TopMost プロパティを true に設定することにより、最上位フォームとして表示されます。このコードを実行すると、最大化表示されたフォームをクリックしても、最上位フォームがそのフォームの下に隠れることがなくなります。この例で定義されるメソッドは、他のフォームから呼び出されることを前提にしています。
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
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: 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.set_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.set_Size(new Size(300, 300)); // Set the position of the top most form to center of screen. topMostForm.set_StartPosition(FormStartPosition.CenterScreen); // Display the form as top most form. topMostForm.set_TopMost(true); topMostForm.Show(); } //CreateMyTopMostForm

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Form.TopMost プロパティのページへのリンク