c# - How to let user enter an integer and start timer based off on that value -
i in process of creating first c# project, personal time tracking application. pretty basic far before further have timer working properly.
so far timer start / stop , reset. curious thing wanted able user set time , have counter start there.
so if wanted start @ 20 minutes , have count up,
example: 00:20:00 count 20 , add it.
however far have not figured out.
here code:
namespace timetracker { public partial class form1 : form { public form1() { initializecomponent(); timerbox.text = string.format("00:00:00"); } int ss = 0; public void startbutton_click(object sender, eventargs e) { timer1.start(); timer1.enabled = true; timer1.interval = 1000; } public void stopbutton_click(object sender, eventargs e) { timer1.stop(); timerbox.text = timespan.fromseconds(ss).tostring(); } public void resetbutton_click(object sender, eventargs e) { ss = 0; timerbox.text = timespan.fromseconds(ss).tostring(); } private void timer1_tick(object sender, eventargs e) { ss++; timerbox.text = timespan.fromseconds(ss).tostring(); } } }
here application:
any appreciated, can provide more details if like!
edit: since unclear, question is:
what process better coding this, adding integer or if there better way of implementing this?
you can set initial value of ss
variable predefined integer entered user, e.g.
datetime _dt = datetime.parse(timertbox.text); int ss = _dt.second + _dt.minute * 60 + _dt.hour * 3600;
Comments
Post a Comment