将焦点设置在 Windows 窗体中的 DateTimePicker 控件中的日期字段上
我的代码中有一个 DateTimePicker
控件。我使用了自定义格式。
this.dateTimePickerDate.CustomFormat = "dd/MM/yyyy";
this.dateTimePickerDate.Value = System.DateTime.Now;
现在的要求是关注控件的日期部分。例如,如果此控件显示 30/06/2011,在 form_load 之后,则应选择日期部分中的 30
,否则光标将位于 0
之后>30。
提前致谢。
I've a DateTimePicker
control in my code. And I have used a custom format.
this.dateTimePickerDate.CustomFormat = "dd/MM/yyyy";
this.dateTimePickerDate.Value = System.DateTime.Now;
Now the requirement is to focus on the date part of the control. For example if this control shows 30/06/2011, after the form_load, then 30
from the date part should be selected or the cursor will be after the 0
in 30
.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这段代码有帮助:
在表单加载时将焦点设置为 datetimepicker。
Maybe this code helps:
And on form load set focus to datetimepicker.
正如建议的这里,我认为这是不可能的。
在该链接中还建议了一种棘手的解决方法(即,当日期时间选择器获得焦点时,以编程方式按向右的箭头),但这可能会导致意外的副作用。
As suggested here, I don't think that's possible.
In that link is also suggested a tricky workaround (i.e. programmatically press the arrow to the right when the datetimepicker has got the focus) but that could lead to unexpected side-effects.