I'm currently making a payroll system for our thesis and I'm having trouble when it comes to Time In Time Out. Our panel said that we should put only one button and one textbox. How should I do that. Thanks in advance.

  • get the button to write to a list or an array a timestamp so whenever the button is pressed the current date/time is logged. When you want to "total up" the time spent "in" (time_in_total, for example) you create a nested loop - the outer one iterates the entire array, the inner loop iterates over two array elements (1,2 then 3,4 then 5,6 etc.) and works out the time difference (your "time out" minus your "time in") and add this to a total - display this in your text box, for example. – Kinnectus Aug 24 '15 at 10:21

You need a timer control and and a single start/stop button. On the first click of the button set the timer to enabled. Show the timer's elapsed time in your textbox. On the next click check if the timer is enabled then measure the timespan between now and when the timer was started.

Full example with code is here: http://markb.co.uk/creating-a-simple-stopwatchtimer-application-with-c-windows-forms.html

  • I already have a timer and a database connection – user487667 Aug 24 '15 at 10:41
  • Use cases: 1. First use (Time in): Button clicked -> Record time to database -> Set time variables to current time -> Start timer 2. Second use (Time out): Button clicked -> Stop timer -> Record elapsed time to database -> Stop timer 3. Repeat case 1. 4. Repeat case 2. – banavalikar Aug 24 '15 at 10:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.