1. Herfried K. Wagner’s VB.Any
  2. .NET
  3. Frequently Asked Questions

Determining which mouse buttons are pressed in the Click event handler

Determining which mouse buttons are pressed in the 'Click' event handler
<URL:https://dotnet.currifex.org/dotnet/faqs/clickmousebuttons/en/>
----------------------------------------------------------------------------

Determining which mouse buttons are pressed in the 'Click' event handler

Although the 'e' parameter is typed as 'EventArgs' in the event handler's
signature, it contains a MouseEventArgs object exposing information about
the buttons being pressed when the event handler gets called.  The code
sample below displays information about the mouse buttons when the user
clicks a form:

\\\
Private Sub Form_Click( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
) Handles MyBase.Click
    If TypeOf e Is MouseEventArgs Then
         Dim Args As MouseEventArgs = DirectCast(e, MouseEventArgs)
         MsgBox(Args.Button.ToString())
    End If
End Sub
///

Some controls like the button control will only raise the 'Click' event if
the left mouse button is pressed and thus won't reveal this information for
clicks with other mouse buttons.