This is behavior by design.
In WinForms
The System.Windows.Forms.DateTimePicker
relies on Win32 API components. That means much of the control rendition and interaction code is native code and cannot easily be changed from within .NET.
You can attempt something like this, subclassing DateTimePicker
and overriding the WndProc
handler, so you can write your own implementation of the WmDateTimeChange
function (original here) and force the day of value
to the same day as validTime
as you detect a month jump. Such modifications are likely to break in future versions of Windows and therefore discouraged for anything other than learning and experimenting.
In WPF
The DatePicker
uses a Calendar
control to represent its popup.
When we look in Reference Source what happens when the actions OnNextClick
and OnPreviousClick
are invoked from the months view, we can see that the DiscardDayTime
function is called to switch to the first of the target month:
return new DateTime(d.Year, d.Month, 1, 0, 0, 0);
I would have suggested to subclass that control and override those event handlers with code to preserve the day, and handle the cases where the target month has less days than the current month, but I'm afraid that the Calendar
instance used by the DatePicker
implementation is not accessible from user code. The DatePicker
also does not expose those internal events as far as I could see.