Here is how to force to show-up, and activate, the dropdown calendar of the standard .Net DateTimePicker control, using VB.Net.
The sample code is tested on .Net 4.0, but should work on all .Net framework version.
Code Snippet
- Dim dateTimePickerControl As DateTimePicker
-
- Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
-
- Public Sub DropDownCalendar()
- Const WM_LBUTTONDOWN As Int32 = &H201
- Const WM_LBUTTONUP As Int32 = &H202
-
- Dim x As Integer = Me.dateTimePickerControl.Width - 10
- Dim y As Integer = CInt(Me.dateTimePickerControl.Height / 2)
- Dim lParam As Integer = x + y * &H10000
-
- 'click down, adn show the calendar
- SendMessage(Me.dateTimePickerControl.Handle, WM_LBUTTONDOWN, CType(1, IntPtr), CType(lParam, IntPtr))
-
- 'click-up, and activate the calendar (without this the calendar is showed, but is not active, and doesen't works as expected)
- SendMessage(Me.dateTimePickerControl.Handle, WM_LBUTTONUP, CType(1, IntPtr), CType(lParam, IntPtr))
- End Sub