View contents of this chapter

Mouse Events & Controls

All the mouse events are associated with controls. You will find mouse events listed for almost every control as well as forms. Windows provides click-related events in the following order:

  •  MouseDown 
  •  MouseUp 
  •  Click 
  •  Dblclick 
  •  MouseUp 

The MouseDown, MouseMove, & MouseUp event procedures require these four arguments:

  • intButton: Describes the button pressed: 1 for the left button, 2 for the right, and 4 for both buttons (or for center button if you a three button mouse).
  • intShift: Describes whether the user pressed Alt, Ctrl, or Shift while moving or clicking the mouse.
  • sngX: The horizontal twip value where the user clicked or moved the mouse.
  • sngY: The verticaltwip value where the user clicked or moved the mouse.

Play Sound Visual Basic generates a movement event after the user moves the mouse every 10 to 15 twips.

The following code tests whether the user pressed Shift, Ctrl, or Alt key in conjunction with the mouse button:

Private Sub cmdTest_MouseDown(intButton As Integer, _
intShift As Integer, sngX As Single, sngY As Single)
   Dim intState As Integer
   intState = intShift And 7 ' special bitwise And
   Select Case intState
      Case 1
            ' Code for Shift combinations
      Case 2
            ' Code for Ctrl combinations
      Case 3
            ' Code for Alt combinations
      Case 4
            ' Code for Shift + Ctrl combinations
      Case 5
            ' Code for Shift + Alt combinations
      Case 6
            ' Code for Ctrl + Alt combinations
      Case 7
            ' Code for Shift + Ctrl + Alt combinations
    End Select
End Sub

Play Sound The special And comparison tests an internal bit flag value to determine which key the user pressed along with the mouse event.


© Universal Teacher Publications        INDEX Previous Screen Next Screen