DateTimePicker: How to close Month Calendar using code?


  • Hi there!

    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 Sub
    Is it possible to change this code to CLOSE the Month calendar?

    Best regards,


    Friday, October 26, 2012 7:37 PM

All replies

  • 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
        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)
            End If
            If GetAsyncKeyState(&H1) And MonthCalOnOff = 1 Then
            End If
            MonthCalOnOff = MonthCalOnOff + 1
        End Sub
    End Class

    You've taught me everything I know but not everything you know.

    Saturday, October 27, 2012 12:18 AM
  • Hi, MonkeyBoy! Thanks to reply!

    I'm not using MonthCalendar. I'm using DateTimePicker and I want to dropdown and colapse it's Month calendar programmatically.

    Best regards,


    Tuesday, October 30, 2012 8:37 PM
  • Hi

    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

    Tuesday, October 30, 2012 8:58 PM
  • 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.

    Best regards,


    • Edited by Oric.CQ Wednesday, October 31, 2012 12:13 AM
    Tuesday, October 30, 2012 11:51 PM