程序时将时间值设置为DateTimePicker [英] Set time value to DateTimePicker programmactically
问题描述
大家好,
这对大多数人来说都是一个非常简单的问题。我在网上搜索了一整天,我无法得到我想要的答案。
帮助我!
我有一个DateTimePicker。 其自定义格式hh:mm tt 。
现在,如果有人在DateTimePicker中更改了值,例如上午12:33,我需要将日期移至上午12:35。
在事件LostFocus上我能够检索所有信息:
DateTimePicker.Value()。小时
DateTimePicker.Value()。Min
并操纵值,无论是增加还是减少。
现在,我该如何回馈修改后的值为DateTimePicker
DateTimePicker.Value()= ??????
谢谢,
Skunkhead:)
Hi guys,
This is a very simple question for most of you. I was searching in web for the whole day and I'm not able to get the answer which I want.
Help me!
I have a DateTimePicker. Its Custom Format "hh:mm tt".
Now if someone changed the value in DateTimePicker e.g 12:33 AM, I need move the date to 12:35 AM.
On event LostFocus I'm able to retrieve all the information:
DateTimePicker.Value().Hour
DateTimePicker.Value().Min
and manipulate the values, whether to increase or decrease.
Now, how do I assinged back the modified values to DateTimePicker
DateTimePicker.Value() = ??????
Thanks,
Skunkhead :)
推荐答案
处理 DateTimePicker会更简单。 ValueChanged
,然后重新设置值,如果它与您的过滤条件不匹配(这个if-check对于避免事件引发事件引发事件的无限循环非常重要。)
Would be simpler to handle DateTimePicker.ValueChanged
, and then re-set the value if it does not match your filter criteria (this if-check is important to avoid an endless loop of event raising event raising event).
差不多。
Almost.
MyDateTimePicker.Value = DateTime.Now
属性 Value
(属性,不是函数!)是类型 DateTime
,它具有所有时间算术你需要的操作。使用 DateTime
进行算术运算,而不是 DataTimePicker
,读取或写入 Value $的值c $ c>一次。
The property Value
(property, not function!) is if the type DateTime
which has all the time arithmetic operation you need. Do arithmetic with DateTime
, not DataTimePicker
, read or write the value of Value
at once.
这篇关于程序时将时间值设置为DateTimePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!