It appears that the topmost property sometimes puts my application above all others, but throughout my testing it has been very weird in that sometimes it works and the window remains above all other (external application) windows, but sometimes it does nothing at all. I have even tried using the WS_EX_TOPMOST flag by setting it with the Win32 API call to setWindowLong(). None of them keep the window on top. Is there another way to keep a window on top of every open window besides using topmost? Or is there something else I should know about topmost?
+1
A:
In addition to Form.TopMost
you can try the Win32 API SetForegroundWindow.
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
public static extern bool SetForegroundWindow(IntPtr hwnd);
Then call SetForegroundWindow(this.Handle)
.
Brian R. Bondy
2010-02-15 16:14:55
+1
A:
I've had luck with the following win32 api calls:
const int SW_SHOW = 5;
BringWindowToTop(form.Handle);
ShowWindow(form.Handle, SW_SHOW);
Ken
2010-02-15 16:19:22
+1
A:
I simply use this:
form.TopLevel = true;
form.TopMost = true;
which makes the window top-level (i.e. it has no parent and behaves as the main form of the application), then ensures that it is topmost (i.e. displays above all other non-topmost windows). It has always worked like a charm.
Note that I do this before I show the window.
Pierre
2010-03-01 20:24:21