I'm using the following code to OPEN the DateTimePicker's month calendar via code:
Public Sub DropDownCalendar() Const WM_LBUTTONDOWN As Int32 = &H201 Const WM_LBUTTONUP As Int32 = &H202 Dim x As Integer = myDateTimePickerControl.Width - 10 Dim y As Integer = CInt(myDateTimePickerControl.Height / 2) Dim lParam As Integer = x + y * &H10000 'click down, adn show the calendar SendMessage(myDateTimePickerControl.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(myDateTimePickerControl.Handle, WM_LBUTTONUP, CType(1, IntPtr), CType(lParam, IntPtr)) End SubIs it possible to change this code to CLOSE the Month calendar?
This code will open and close a month calendar using the left mouse button
Imports System.Runtime.InteropServices Public Class Form1 Dim MonthCalOnOff As Integer = 0 Dim MonthCal As New MonthCalendar <DllImport("user32.dll")> Public Shared Function GetAsyncKeyState(ByVal vKey As Int32) As UShort End Function Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Mouse_Down(sender As Object, e As MouseEventArgs) Handles Me.MouseDown If MonthCalOnOff = 2 Then MonthCalOnOff = 0 End If If GetAsyncKeyState(&H1) And MonthCalOnOff = 0 Then MonthCal.Location = New Point(0, 100) Me.Controls.Add(MonthCal) End If If GetAsyncKeyState(&H1) And MonthCalOnOff = 1 Then Me.Controls.Remove(MonthCal) End If MonthCalOnOff = MonthCalOnOff + 1 End Sub End Class
You've taught me everything I know but not everything you know.
- Edited by Mr. Monkeyboy Saturday, October 27, 2012 12:46 AM
Doesn't make sense! If user opens the drop down, then you try to close it - where is the logic in that? The DateTimePicker doesn't have a close drop down method or anything like it. You could Hide it I suppose, but again, think how confused the user would be?
Regards Les, Livingston, Scotland
Hi, Leshay! Thanks to reply!
Belive me, I have my reasons for try this approach. I know that trere is no VB.Net method for show or colapse the DateTimePicker's month calendar. That's the reason why I'm looking for some help in this forum.
- Edited by Oric.CQ Wednesday, October 31, 2012 12:13 AM