A few minutes ago I encountered a weird problem with TopMost. I created a topmost form (WinForms) did some tabbing and everything was fine.
Then I tried to open a computer game (fullscren-windowed) which means the game is fullscreen but in a windowed mode which means you can still overlay it with forms. Everything fine until I opened my Browser for example (could be any other program (editor)). Just as a quick side note I have two monitors.
- I tabbed out of the computer game (where my form is TopMost) into the browser
- I clicked somewhere in the browser (url)
- I tabbed back into the game, clicked somewhere in the game (my form is still TopMost)
- I do step 1-3 again and suddenly my form (topmost) disappeared.
This happens every time I do this and this problem can be reproduced on at least 2 other
machines.
EDIT:
I tried to implement the suggested solution
public partial class Form1 : Form
{
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOACTIVATE = 0x0010;
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
public void setTOP()
{
SetWindowPos(this.Handle, new IntPtr(-1), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.setTOP();
}
}
But this didn’t work.
It’s a horrible solution but it’s better than nothing so far.
I implemented a timer which calls topmost every x seconds. Just like I said, it’s not a good solution but the only one which came to my mind. I’ll continue to work on this but for the meantime this is what i do.