event MouseDown (Button as Integer, Shift as Integer, X as OLE_XPOS_PIXELS, Y as OLE_YPOS_PIXELS)
Occurs when the user presses a mouse button.

 TypeDescription 
   Button as Integer An integer that identifies the button that was pressed to cause the event.  
   Shift as Integer An integer that corresponds to the state of the SHIFT, CTRL, and ALT keys when the button specified in the button argument is pressed or released.  
   X as OLE_XPOS_PIXELS A single that specifies the current X location of the mouse pointer. The X value is always expressed in container coordinates.  
   Y as OLE_YPOS_PIXELS A single that specifies the current X location of the mouse pointer. The X value is always expressed in container coordinates.  

Use a MouseDown or MouseUp event procedure to specify actions that will occur when a mouse button is pressed or released. Unlike the Click and DblClick events, MouseDown and MouseUp events lets you distinguish between the left, right, and middle mouse buttons. You can also write code for mouse-keyboard combinations that use the SHIFT, CTRL, and ALT keyboard modifiers. Use the DateFromPoint property to get the date from cursor.

The following VB sample prints the date from the cursor:

Private Sub Calendar1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    With Calendar1
        Dim d As Date
        d = .DateFromPoint(X / Screen.TwipsPerPixelX, Y / Screen.TwipsPerPixelY)
        If Not (d = 0) Then
            Debug.Print FormatDateTime(d)
        End If
    End With
End Sub

The following Access sample displays a message when user clicks a date:

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90

' Converts twips corrdinates to pixels coordinates
Private Sub Twips2Pixels(X As Long, Y As Long)
    Dim hDC As Long
    hDC = GetDC(0)
    X = X / 1440 * GetDeviceCaps(hDC, LOGPIXELSX)
    Y = Y / 1440 * GetDeviceCaps(hDC, LOGPIXELSY)
    ReleaseDC 0, hDC
End Sub

Private Sub Calendar1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
 With Calendar1
        Dim d As Date
        Twips2Pixels X, Y
        d = .DateFromPoint(X, Y)
        If Not (d = 0) Then
            MsgBox FormatDateTime(d)
        End If
    End With
End Sub

Send comments on this topic.
© 1999-2008 Exontrol Inc, Software. All rights reserved.