想要更改 DateTimePicker.Value.TimeOfDay,但它是只读的
我正在尝试检查 DateTimePicker 控件中输入的时间并将其更正为 C# 中最接近的可接受值
if (Summer1.Value.TimeOfDay > Summer2.Value.TimeOfDay)
Summer1.Value.TimeOfDay = Summer2.Value.TimeOfDay;
它给了我以下内容:
无法将属性或索引器“System.DateTime.TimeOfDay”分配给 -- 只读
为什么它将 DateTimePicker 对象作为系统时间处理? 我在 VS 2003 中找不到与控件的只读状态相关的任何内容。
I am trying to check an entered time in a DateTimePicker control and correct it to the closest acceptable value in C#
if (Summer1.Value.TimeOfDay > Summer2.Value.TimeOfDay)
Summer1.Value.TimeOfDay = Summer2.Value.TimeOfDay;
It gives me the following:
Property or indexer 'System.DateTime.TimeOfDay' cannot be assigned to
-- it is read only
Why does it handle the DateTimePicker object as a system time?
I could not find anything related to Read-Only state of the control in VS 2003.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Summer1.Value
是DateTimePicker
的属性,其类型为DateTime
。该属性是可分配的。您正在尝试分配
Summer1.Value.TimeOfDay
- 这是DateTime
对象Summer1.Value
的属性 - 并且此属性没有DateTime
类中的设置器。应该可以正常工作,但可能不会给你想要的结果。
最接近您想要的输出将是这样的
Summer1.Value
is the property ofDateTimePicker
and it has type ofDateTime
. This property is assignable.You're trying to assign
Summer1.Value.TimeOfDay
- which is a property ofDateTime
objectSummer1.Value
- and this property does not have setter inDateTime
class.should work fine but may not give you the desired result.
The closest to your desirable output will be something like