DateTimePicker 自动移动到下一个日期部分
目前,在使用日期时间选择器时,输入月份后,您必须点击向右箭头或“/”才能将其移至日期。是否有一个我可以设置的属性或一种方法可以知道该月已完成并在用户完成该天后移至该日并移至该年?这与旧 FoxPro/Clipper 时代编写的应用程序的行为相同。
Currently, when using the datetimepicker, after you enter the month you have to either hit the right arrow or the "/" for it to move to the day. Is there a property that I can set or a way to know that the month is done and move to the day and move to the year after the user is done with the day? This is the same behavior with applications written in the old FoxPro/Clipper days.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如@Wael Dalloul 所说,没有财产可以做你想做的事。经过大量的摆弄和 Spy++ 工作后,我找到了以下解决方案:
继承
System.Windows.Forms.DateTimePicker
,并声明标志的私有字段:为 Win API 定义常量和结构:
为了使用 Win API,还需要包含 System.Runtime.InteropServices 的 using 语句。
重写
OnKeyDown
并根据按下的键是否为数字来设置或清除标志(并清除下面的第二个标志)。重写
WndProc
并捕获WM_REFLECT+WM_NOTIFY
消息,从lParam
中提取NMHDR
,然后设置另一个如果代码为-759,则标记(在用键盘完全填写其中一个字段并选择日期后触发此事件)。重写
OnKeyUp
,如果两个标志都已设置并且按下的键是数字,则使用WM_KEYDOWN
手动调用base.WndProc
,然后是一个带有Keys.Right
的WM_KEYUP
,然后清除您的标志。你可以将这些消息的lParam
设置为0而不用管它,而HWnd
当然是this.Handle
。对于代码中缺少空白行表示歉意,但它不会与空白行一起正确显示,所以我将它们删除了。相信我,这是更具可读性的版本。
As @Wael Dalloul says, there is no property to do what you want. After a lot of fiddling and Spy++ work, I came upon the following solution:
Inheriting from
System.Windows.Forms.DateTimePicker
, and declaring private fields for flags:Defining constants and structs for Win API:
It's also necessary to include a using statement for
System.Runtime.InteropServices
in order to use Win API.Override
OnKeyDown
and set or clear a flag based on if the key pressed was a number (and clear the second flag below).Override
WndProc
and trap theWM_REFLECT+WM_NOTIFY
message, extract theNMHDR
fromlParam
, then set another flag if the code is -759 (this event is triggered after one of the fields is completely filled in with the keyboard and a date is selected).Override
OnKeyUp
and if both flags are set and the key pressed was a number, manually callbase.WndProc
with aWM_KEYDOWN
followed by aWM_KEYUP
withKeys.Right
, then clear your flags. You can set thelParam
of these messages to 0 and not worry about it, andHWnd
is of coursethis.Handle
.Apologies for the lack of blank lines in the code, but it wouldn't display right with the blank lines, so I took them out. Trust me, this is the more readable version.
它将在 winforms datetimepicker 上的
值更改事件上工作,粘贴以下代码
It will work on winforms datetimepicker
on value change event paste the below code
没有属性使它像你想要的那样工作,我认为你必须处理按键事件并通过代码来完成。
There is no Property to make it work like what you want, I think you have to handle keypress event and do it by code.