tags:

views:

166

answers:

4

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?

+1  A: 

Try your mainform's Deactivate event

junmats
A: 

Control.LostFocus Event

Ngu Soon Hui
OP says LostFocus is not fired, but you recommend it? Can you give an example of why it might not work?
Wil P
A: 

I just tested Deactivate and that works for me

Crash893
+2  A: 

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.

Neil N