how to know when form lost its focus


  • Hi,

                Is there any way to know when Form lost its focus? I have tried Deactivate event but it does not helped me. Thanks in advance


    Wednesday, April 26, 2006 4:32 AM


  • I believe you want the Leave event.


    Wednesday, April 26, 2006 4:50 AM

All replies

  • I believe you want the Leave event.


    Wednesday, April 26, 2006 4:50 AM
  • Thanks for your help - It works.

    Is there any way to know when application lost the focus. I mean even my application in on and he start working on another application.


    Wednesday, April 26, 2006 4:58 AM
  • If your app has multiple open forms that could have focus, then Leave will tell you if one form loses focus, you could use Application.OpenForms to iterate through all forms and see if any of those have the focus, beyond that I don't know of a way.


    Wednesday, April 26, 2006 5:00 AM

    Try this...

    //We aren't the active window, so relax a bit and free up the CPU

    if (ActiveForm != this)


    //Does not have focus...


    Wednesday, April 26, 2006 5:20 AM
  • Let me give little bit idea what I am doing.


    I have an application which shows user news. If user is already in news form then no notification is given. But if it is working on another form then user is notified using a popup. I have done this with the help of “cgraus”.


    Now problem is if user has start working on an application lets say word and my application is running too. But application not have focus. Is there any why to capture that event.


    Thanks for your help

    Wednesday, April 26, 2006 6:48 AM

    One way would be to use the flash functions of the task bar and make it flash like the other apps do. Or use a Tray icon and when ever there is news have a popup rise from the bottom like the MSN Messenger does.

    Wednesday, April 26, 2006 9:14 AM
  • But in my application Form1_Leave doesn't get fired.
    Kindly figure out what is the problem with the Leave and Enter events.

    Tuesday, July 22, 2008 9:11 AM
  • Dear Rachel,

    this original post is dated and answered over 2 years ago, it would have been more polite and effective to have started your own post.

    Leave and Enter are events that get fired when your form is visible and the mouse enters or leaves the visible part of the form...

    For losing focus, it's really easy, have a look at:

    public Form1()



    this.LostFocus += new EventHandler(Form1_LostFocus);


    void Form1_LostFocus(object sender, EventArgs e)


    MessageBox.Show("I lost focus");


    The improbable we do, the impossible just takes a little longer. - Steven Parker
    • Edited by Jan Van der Haegen Tuesday, July 22, 2008 9:50 AM Added Leave-Enter explanation
    Tuesday, July 22, 2008 9:49 AM