开发者

How to set DateTimePicker to auto update?

开发者 https://www.devze.com 2023-01-02 01:23 出处:网络
I\'ve added a date time picker to a form. Initially its value is set to the DB sever date and time. Once its value is set, I need it to automatically update itself so that it always shows the DB serve

I've added a date time picker to a form. Initially its value is set to the DB sever date and time. Once its value is set, I need it to automatically update itself so that it always shows the DB server Date and time. How can I do this? Do I have to devel开发者_高级运维op a custom control?

Thanks in advance!


You could set up a System.Windows.Forms.Timer that fires a timeout event every X seconds (200ms,500ms,1sec.. whatever) and in the event handler increment the DateTime of the picker by the timeout amount. This will gradually stray away from the DB server by small amounts because of inexact timing.

Alternatively you could set up the same timer instead of incrementing the time in your picker, you can keep requesting the latest DB server time and setting the picker to that.

If the main purpose is to maintain appearances I would use the first option, and then re-request the DB time only when I need the most up to date time for an operation of some sort.

0

精彩评论

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