开发者

use dateTimePIcker to set timer interval

开发者 https://www.devze.com 2023-02-20 12:33 出处:网络
I want to use dateTimerPicker Time format {mm:ss} and use it in timer.interval. meaning converting the dateTimePicker value to double and开发者_StackOverflow社区 back again.

I want to use dateTimerPicker Time format {mm:ss} and use it in timer.interval.

meaning converting the dateTimePicker value to double and开发者_StackOverflow社区 back again.

any thoughts ?


Use this:

timer.Interval = dateTimePicker.Value.TimeOfDay.TotalMilliseconds


timer.interval is in milliseconds. (mm * 60 + ss) * 1000 = time in milliseconds. Or easier is DateTime.TimeOfDay.TotalMilliseconds.

Perhaps it is also beter to use the TimeSpan object instead of the DateTime. Because you are not using the Date part of it. (Maybe for other reasons which I don't know)

You then can use the TimeSpan.TotalMilliseconds property.

TimeSpan on MSDN

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号