tags:

views:

705

answers:

2

I would like to display a status window in my C# Windows Forms application that informs the user when the application is waiting to acquire a lock. This is an application-defined thing, however, the window should be visible and always remain on top of all other windows of my application, even when the user clicks on another window (like for example the larger main window behind it).

It must not be modal (so ShowDialog() cannot be used) because the app needs to keep trying in the background and close the window automatically if the lock could eventually be acquired, and it really should not be top-most for the entire window station (i.e. all applications running in that terminal session).

I know the Form.TopMost property, but it can only bring and keep a single window above all others, even those from other applications. This is clearly not what I'm looking for.

I know that this is possible, I've seen it many times before in other applications. I just don't know how it can be done.

+2  A: 

If you pass your main form into the Show method of the status form, it will stay on top of the main form, but not on top of other applications. So, in the main form you can have code like so:

StatusForm statusForm = new StatusForm();
statusForm.Show(this);

However, this will only point out one single window of your application as the owner.

Fredrik Mörk
It also seems to work with multiple windows. (At least multiple instances of the same Form class.) All of them remain in front of the owning window.
LonelyPixel
+2  A: 

You have to set the Owner property of the child form to the parent form, and use Show to show the child form.

Timbo
Thank you, both solutions work just fine. Unfortuinately I can only mark one answer as accepted solution (but up-vote both). I also found out that it is good to set the ShowInTaskbar property of the owned windows to false so that they won't mess up the taskbar and Alt+Tab window list.
LonelyPixel