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.
.net – DateTimePicker automatically move to next datepart
.netdatetimepicker
Best Solution
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.