I'm looking to create a form in C# that cannot accept focus, i.e. when I click a button on the form, focus is not stolen from the application that currently has the focus.
See the Windows on-screen keyboard for an example of this. Note that when you click a button, the focus is not taken from the application you're currently using.
How can I implement this behaviour?
Update:
Turns out it's as simple as overriding the CreateParams
property and adding WS_EX_NOACTIVATE
to the extended window style. Thanks for pointing me in the right direction!
Unfortunately this has the undesirable side-effect that it messes with form movement, i.e. you can still drag and drop the form around the screen but the window's border is not displayed while dragging so it's difficult to precisely position it.
If anyone knows how to solve this it would be appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…