Right Mouse Click or Left Mouse Click - Detecting Which

J

jcrouse

I have the following mouse events assigned to a label control. Is the a way
I can tell which mouse button the users has clicked with?

Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

End Sub

Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown

myMousedown = lblP1JoyUp.Name

bMouseMove = False

lblP1JoyUp.BringToFront()

clrBGColor = lblP1JoyUp.BackColor

If lblP1JoyUp.BackColor.Equals(Color.Transparent) Then

bTransCk = True

lblP1JoyUp.BackColor = Color.Black

End If

mouseX = Cursor.Position.X - lblP1JoyUp.Location.X

mouseY = Cursor.Position.Y - lblP1JoyUp.Location.Y

lblP1JoyUp.Cursor = Cursors.Hand

End Sub

Private Sub lblP1JoyUp_MouseMove(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseMove

Dim lblP1JoyUp As Label = DirectCast(sender, Label)

Static LastCursor As Point

Dim NowCursor As Point = New Point(Cursor.Position.X,
Cursor.Position.Y)

If Point.op_Inequality(NowCursor, LastCursor) Then

If myMousedown = lblP1JoyUp.Name Then

lblP1JoyUp.Location = New
System.Drawing.Point(Cursor.Position.X - mouseX, Cursor.Position.Y - mouseY)

bMouseMove = True

End If

LastCursor = Cursor.Position

End If

End Sub

Private Sub lblP1JoyUp_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseUp

Dim lblP1JoyUp As Label = DirectCast(sender, Label)

If bTransCk = True Then

lblP1JoyUp.BackColor = Color.Transparent

End If

lblP1JoyUp.BackColor = clrBGColor

myMousedown = ""

lblP1JoyUp.Cursor = Cursors.Default

End Sub

Thank you,
John
 
H

Herfried K. Wagner [MVP]

jcrouse said:
I have the following mouse events assigned to a label control.
Is the a way I can tell which mouse button the users has
clicked with?

Inside the handlers for 'MouseDown' and 'MouseUp', you can check 'e.Button'.
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?amNyb3VzZQ==?= said:
How? I've tried some diffenert syntax and can't seem to get it right.

\\\
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then
...
ElseIf e.Button = MouseButtons.Right Then
...
Else
...
End If
End Sub
///
 
J

jcrouse

Resolved....Seems I was putting it in the click event instead of the mouse
down event.

Thank you,
John

Herfried K. Wagner said:
\\\
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
 
H

Herfried K. Wagner [MVP]

* "jcrouse said:
Resolved....Seems I was putting it in the click event instead of the mouse
down event.

It will work in the 'MouseUp' event too, but as you say, not in the
'Click' event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top