VBA/Excel/Access/Word/Forms/Mouse

Материал из VB Эксперт
Перейти к: навигация, поиск

Check the mouse button in MouseDown event action listener

   <source lang="vb">

Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X As Single, Y As Single)

   If Button = 1 Then " acLeftButton 
       MsgBox "You pressed the left button." 
   ElseIf Button = 2 Then "acRightButton 
       MsgBox "You pressed the right button." 
   ElseIf Button = 4 Then "acMiddleButton 
       MsgBox "You pressed the middle button." 
   End If 

End Sub

</source>
   
  


Display Mouse Button, Shift key and Position X and Position Y

   <source lang="vb">

Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

   Cells(2, "A").Value = Button
   Cells(2, "B").Value = Shift
   Cells(2, "C").Value = X
   Cells(2, "D").Value = Y

End Sub

</source>
   
  


Writing the Form_MouseDown Event Procedure

   <source lang="vb">

Private Sub Form_MouseDown(Button As Integer,Shift As Integer, X As Single, Y As Single)

   Select Case Shift 
       Case 0 
           MsgBox "You did not press a key." 
       Case 1 " or acShiftMask 
           MsgBox "You pressed SHIFT." 
       Case 2 " or acCtrlMask 
           MsgBox "You pressed CTRL." 
       Case 3 
           MsgBox "You pressed CTRL and SHIFT." 
       Case 4 " or acAltMask 
           MsgBox "You pressed ALT." 
       Case 5 
           MsgBox "You pressed ALT and SHIFT." 
       Case 6 
           MsgBox "You pressed CTRL and ALT." 
       Case 7 
           MsgBox "You pressed CTRL, ALT, and SHIFT." 
   End Select 

End Sub

</source>