How to detect when an application loses focus?

后端 未结 2 1485
难免孤独
难免孤独 2020-12-11 04:34

I created a usercontrol in c#, Leave and LostFocus are not fired if I switch to another program. How can I detect if the app loses focus?

相关标签:
2条回答
  • 2020-12-11 05:15

    If you switch to a differnt app, your custom control DIDN'T lose focus. At least not within the app it is in.

    If you come back to your app, such as hitting it on the taskbar (and not by clicking on another control on the same app), your control will still have "focus".

    This is where Form.Deactivate comes in handy.

    0 讨论(0)
  • 2020-12-11 05:25

    Try your mainform's Deactivate event

    0 讨论(0)
提交回复
热议问题