Zeebok Zeebok - 1 year ago 68
C# Question

How to get form going to "Background state" Event in c#

Hope you all are fine. My question is, we have form_load event in c# forms. I want to do some job when my form1 will go in background and form2 will come to foreground. I have wasted my time in searching that, but could not found any help in this regard.
Your precious help even a little pointer can solve my issue. Thanks

Answer Source

Form.Activated Event


Occurs when the form is activated in code or by the user.

Form.Deactivate Event


Occurs when the form loses focus and is no longer the active form.

UPDATE to start and stop the timer:

class Form1: Form{
    void Form_Load(object sender, EventArgs arg)
        this.Activated += form_Activate;
        this.Deactivate += form_Deactivate;

    void form_Activate(object sender, EventArgs arg){

    void form_Deactivate(object sender, EventArgs arg){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download