0

how can i catch when the form not used by the user i need to make form that will closed after 5 minutes if the user don't make any action on this form with C# Code Please help me

I make this code for closing system after 5 minutes

        Timer.Interval = (1000) * (300); 
        Timer.Enabled = true;
        Timer.Start();  

 private void Timer_Tick(object sender, EventArgs e)
        {
            Close(); 
        }

But i need to make this code active if the form not used .

4

2 回答 2

0

write this.

    private void Form1_Activated(object sender, EventArgs e)
    {
        Timer.Enabled = false;
    }

    private void Form1_Deactivate(object sender, EventArgs e)
    {
        Timer.Enabled = true;
    }
于 2013-02-12T08:20:32.357 回答
0

Use the "Leave" event to manage your exit logic, like say trigger the timer.. The leave event gets fired on loosing focus.

于 2013-02-12T08:23:25.280 回答