Form.TopMost Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets a value indicating whether the form should be displayed as a topmost form.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public bool TopMost { get; set; }

Property Value

Type: System.Boolean

true to display the form as a topmost form; otherwise, false. The default is false.

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.

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. The first form, named bottomForm, is displayed maximized, using the WindowState property, to better demonstrate the abilities of the topmost form. 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 = new Form();
   // Display the lower form Maximized to demonstrate effect of TopMost property.
   bottomForm.WindowState = FormWindowState.Maximized;
   // Display the bottom form.
   // 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;

.NET Framework
Available since 1.1
Return to top