In the DateTimePicker
when user clicks DropDown
button, a calendar gets displayed. I don't want to show calendar on the DropDown event.
Is there some way to overwrite this event and to show custom form when user clicks DropDown button??
In the DateTimePicker
when user clicks DropDown
button, a calendar gets displayed. I don't want to show calendar on the DropDown event.
Is there some way to overwrite this event and to show custom form when user clicks DropDown button??
I don't want to show calendar on the DropDown event.
You can prevent the calendar from being displayed by setting the control's ShowUpDown
property to true
. Instead of the drop-down calendar, it will instead show a spin button to the side of the DateTimePIcker control that allows the user to select the desired date/time.
Is there some way to overwrite this event and to show custom form when user clicks DropDown button??
Well, yeah, I guess so. You can handle the DropDown
event, which gets raised when the control shows the drop-down calendar. In this event handler, you could display whatever form you wanted. The only problem is that the drop-down calendar is still going to be shown as normal. I don't know how you prevent that from happening.
You can, however, hack around it by forcing the drop-down calendar closed again. To do that, P/Invoke the SendMessage
function and send the control the DTM_CLOSEMONTHCAL
message.
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private const uint DTM_FIRST = 0x1000;
private const uint DTM_CLOSEMONTHCAL = DTM_FIRST + 13;
public static void CloseCalendar(this DateTimePicker dtp)
{
SendMessage(dtp.Handle, DTM_CLOSEMONTHCAL, IntPtr.Zero, IntPtr.Zero);
}
But I can't imagine the reason you would want to do this. If you don't want a calendar or a spin-button control, then you don't want a DateTimePicker. Just use a regular combo box or a drop-down button, then you can display whatever form you want when it is clicked.