locked
right left mouse click RRS feed

  • Question

  • i am using this code and the right mouse click does not work

    Private Sub label1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles labDateTime.MouseClick
        If Windows.Forms.MouseButtons.Left Then
                msgbox("Left")
        else
                 msgbox("right")
        End If
    End Sub
    Saturday, February 7, 2009 1:51 PM

Answers

  • This would be better

     
     
        Private Sub Label1_MouseClick(ByVal sender As System.ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseClick  
     
            Select Case e.Button  
                Case Windows.Forms.MouseButtons.Left  
                    'code  
                Case Windows.Forms.MouseButtons.Middle  
                    'more code  
                Case Windows.Forms.MouseButtons.Right  
                    'more code  
                Case Windows.Forms.MouseButtons.XButton1  
                    'more code  
                Case Windows.Forms.MouseButtons.XButton2  
                    'more code  
            End Select 
     
        End Sub 
     

    Coding for fun
    Saturday, February 7, 2009 2:07 PM
  •  
     
     
        Private Sub Label1_MouseClick(ByVal sender As System.ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseClick  
     
            If e.Button = Windows.Forms.MouseButtons.Left Then 
                MsgBox("Left")  
            Else 
                MsgBox("Right")  
            End If 
     
        End Sub 
     

    Coding for fun
    • Proposed as answer by Arjun Paudel Saturday, February 7, 2009 2:29 PM
    • Marked as answer by Martin Xie - MSFT Wednesday, February 11, 2009 8:10 AM
    Saturday, February 7, 2009 2:04 PM

All replies

  •  
     
     
        Private Sub Label1_MouseClick(ByVal sender As System.ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseClick  
     
            If e.Button = Windows.Forms.MouseButtons.Left Then 
                MsgBox("Left")  
            Else 
                MsgBox("Right")  
            End If 
     
        End Sub 
     

    Coding for fun
    • Proposed as answer by Arjun Paudel Saturday, February 7, 2009 2:29 PM
    • Marked as answer by Martin Xie - MSFT Wednesday, February 11, 2009 8:10 AM
    Saturday, February 7, 2009 2:04 PM
  • This would be better

     
     
        Private Sub Label1_MouseClick(ByVal sender As System.ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseClick  
     
            Select Case e.Button  
                Case Windows.Forms.MouseButtons.Left  
                    'code  
                Case Windows.Forms.MouseButtons.Middle  
                    'more code  
                Case Windows.Forms.MouseButtons.Right  
                    'more code  
                Case Windows.Forms.MouseButtons.XButton1  
                    'more code  
                Case Windows.Forms.MouseButtons.XButton2  
                    'more code  
            End Select 
     
        End Sub 
     

    Coding for fun
    Saturday, February 7, 2009 2:07 PM
  • thanks for the help it worked great
    Sunday, February 8, 2009 12:07 PM
  • Your welcome . By the way you should get in the habit of marking posts as answered when you create a topic and receive a suitable answer and also marking posts as helpful on all topics where you find a post helpful .
    Coding for fun
    Sunday, February 8, 2009 12:32 PM
  • ungrateful wretches!
    Compensating what I don't know yet, with what I do know now.
    Sunday, February 8, 2009 12:50 PM