Search code examples
c#timernumericupdown

how to set a timer based on numericupdown values?


I have a program set up that has 3 numericupdowns. Their names are secondsN, minutesN, and hoursN. I want to set a timer based on the values of the numericupdowns.

Example: if secondsN has a value of 3 then I want the clock to be set to 3 seconds which I think is 3000 milliseconds.

so how can I do this?

Thanks for your help!


Solution

  • You can combine them into a TimeSpan. Then use the TotalMilliseconds property off of that.

    int numberOfHours, numberOfMinutes, numberOfSeconds;
    var timeSpan = new TimeSpan(numberOfHours, numberOfMinutes, numberOfSeconds);
    myTimer.Interval = timeSpan.TotalMilliseconds;