I want to disable the content of a c# windows form if I don't work on it for a certain duration, for example 10 minutes? Is this possible?
-
ok i use timer but it disable my form in amount of time if i use the form or not.... this is my problem? – Hunar Apr 01 '14 at 18:09
-
1A timer and an event handler that all controls/content subscribe too. – jeff Apr 01 '14 at 18:10
-
Have you tried anything so far? - it would be useful to show some effort on your part to solve your issue. – connectedsoftware Apr 01 '14 at 18:10
-
how to make this event ... ant event can do this for me? – Hunar Apr 01 '14 at 18:11
-
Maybe something like this: http://www.codeguru.com/columns/vb/how-to-check-for-application-inactivity-in-.net-2010.htm or this: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.idle(v=vs.110).aspx – John Bustos Apr 01 '14 at 18:13
-
@honar.cs You need to reset the timer on something like a mouse move or a commonly used control being clicked. – tnw Apr 01 '14 at 18:13
2 Answers
As you can read in this question: How to enable ALL controls on a form? you can write a small method that disables ALL controls in your form.
Now for the timer, you can create a timer object that is initialized when you load your form (form load). You make it count down to 10 minutes and when the timer has elapsed you execute your disable function.
To make it count from 10 every time you use the form, you can reset the timer from every event handler, or you can for example make use of the winform being on the foreground or not (discussed here: Determine Whether Program is the Active Window in .NET).

- 1
- 1

- 2,852
- 3
- 30
- 47
You can use GetLastInputInfo
to determine how long ago the user last interacted with the system. see the MSDN
If you only want to keep track of interactions with your form alone you should use a timer and reset it on interaction with your form (as suggested by Christophe)

- 2,992
- 2
- 22
- 33