Mouse button clicks...

lidds

Junior Contributor
Joined
Nov 9, 2004
Messages
210
Is there a way in vb.net that you can tell what mouse button was clicked (i.e. left mouse button) and then perform an operation.

example:

Code:
if left mouse button clicked then
 msgbox("left clicked")
elseif right mouse button clicked then
 msgbox("right clicked")
endif

Thanks

Simon
 
Code:
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
       
 If e.Button = MouseButtons.Right Then
       messagebox.show("Right Click")
Else
       messagebox.show("Left Click")
        End If

End Sub
 
form itself

so if A is pressed i want the form to +1 in a textbox
so if u press 3 diff chars the textbox will have the number 3 in it..you know what i mean?
 
I code in C++/C# , but I believe this should work.

Visual Basic:
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If e.KeyChar = Chr(Keys.A) Then
             textbox1.Text = Integer.Parse(textbox1.text) + 1
        End If
    End Sub

If you wanted it for all keys then:
Visual Basic:
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
         textbox1.Text = Integer.Parse(textbox1.text) + 1
    End Sub
Hope this helps.
-Sean
 
coldfusion244 said:
I code in C++/C# , but I believe this should work.

Visual Basic:
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If e.KeyChar = Chr(Keys.A) Then
             textbox1.Text = Integer.Parse(textbox1.text) + 1
        End If
    End Sub

If you wanted it for all keys then:
Visual Basic:
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
         textbox1.Text = Integer.Parse(textbox1.text) + 1
    End Sub
Hope this helps.
-Sean
Thanks for the help
but none worked..i tried changing a few things but still didnt work.

i think its something in
Visual Basic:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
 
Back
Top