12

I have a form that i want to always be on top whenever it is opened in the application but i dont want it to be on top when the main form is minimized or another application is navigated. I want it to be on top only in my application.

Following the answer in the question : How to make a window always stay on top in .Net?

    this.TopMost = true;

Makes the form on top but the form is still on top when another application is navigated to or the main form is closed.

Pls how do i make the form only on top in the application while enabling user to still work on the main form?

Community
  • 1
  • 1

2 Answers2

17

You are looking for an owned window. It is always on top of the owner and it gets minimized along with the owner. Good examples of owned windows are the various helper windows inside Visual Studio. You can undock them but they'll always stay on top of the VS main window.

You create an owned window by displaying it with the Show(owner) overload. Or by explicitly assigning its Owner property.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
5

Set the top level and then set the owner, example below.

public Form1()
{
    InitializeComponent();
    Form2 f2 = new Form2();
    //top level not really needed
    f2.TopLevel = true;
    f2.Show(this);
}
Sorceri
  • 7,870
  • 1
  • 29
  • 38
  • Setting `TopLevel` to `true` in this situation results in the window staying on top of other applications. If it's set to `false` and has an owner, it will only stay on top of the application. – jahu Nov 03 '17 at 14:10