How do I create an "unfocusable" form in C#?
To disable activation by mouse:
class NonFocusableForm : Form
{
protected override void DefWndProc(ref Message m)
{
const int WM_MOUSEACTIVATE = 0x21;
const int MA_NOACTIVATE = 0x0003;
switch(m.Msg)
{
case WM_MOUSEACTIVATE:
m.Result = (IntPtr)MA_NOACTIVATE;
return;
}
base.DefWndProc(ref m);
}
}
To show form without activation (the only one way that worked for me in case of borderless form):
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr handle, int flags);
NativeMethods.ShowWindow(form.Handle, 8);
Standard way to do this (seems like it doesn't work for all form styles):
protected override bool ShowWithoutActivation
{
get { return true; }
}
If there are other ways of activating the form, they can be suppressed in similar manner.