I have a dialog implemented in WinForms that is shown as a notify dialog on the bottom right of the screen. The problem is that whenever is shown it takes the focus and this happens only when TopMost = true. How can I solve this?
+1
A:
Show the dialog with Show instead of ShowDialog. ShowDialog will be topmost, user has to click it before doing something else (modal) Show will show it as normal.
PoweRoy
2009-11-13 08:08:18
I open it using Show() method already
Cornel
2009-11-13 08:12:26
A:
How about this strategy:
- Show it at startup, then immediately:
- Hide it with ShowWindow( SW_HIDE )
- Never ever close the form, just let it be invisible
- Show it with ShowWindow( SW_SHOWNOACTIVATE )
danbystrom
2009-11-13 09:07:28
+1
A:
You need to inherit from Form and override a couple of properties:
[Flags]
enum WS_EX
{
TOPMOST = 0x00000008,
}
class TopMostForm : Form
{
protected override CreateParams CreateParams
{
get
{
var baseParams = base.CreateParams;
baseParams.ExStyle |= (int)WS_EX.TOPMOST;
return baseParams;
}
}
protected override bool ShowWithoutActivation
{
get { return true; }
}
}
Then just simply Show() on this form and it will be displayed as topmost and inactive.
Konstantin Spirin
2009-11-13 09:35:17
Window style WS_EX_TOPMOST makes your window top-most. If you look at `Form.TopMost` property in Reflector, you'll see that it uses different approach that makes your window active.
Konstantin Spirin
2009-11-14 15:36:13