Mouse location

  • Thread starter Thread starter Adriano
  • Start date Start date
A

Adriano

hello,

is there any code to catch mouse move?
I mean to catch X and Y locations on a form?

tnx in advance,
Adriano
 
Hi Adriano,

Try handling the MouseMove Event and in the event arguments you will be able
to retrieve the Mouse Position Coordinates
something like this
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

Debug.WriteLine(e.X & "," & e.Y)

End Sub

Hope it helps
rawCoder
 
* "rawCoder said:
Try handling the MouseMove Event and in the event arguments you will be able
to retrieve the Mouse Position Coordinates
something like this
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

Debug.WriteLine(e.X & "," & e.Y)

End Sub

Outside this event, you can use 'Cursor.Position' to get the mouse
position.
 
hello Coder,
I tried this but the following error message appears:

Method 'FormClick_MouseMove' cannot handle Event 'MouseMove' because they do
not have the same signature.

any other ideas?
 
Did you use the IDE to get the signature of method .. like from top
ComboBoxes by selecting Base and Overrides and then selecting MouseMove
method. Or did u write it yourself. If later is the case, do try it using
the IDE. You may wanna post the Signture here so that the problem can be
identified.

frankly I dont remember any signature.. not even Form_Load ... so gotta
trust the IDE. Thanx its not C# and the IDe is on our side;-)

Thank You
rawCoder
 
I'm a beginner so I used IDE to write the code,
here is the code:

Private Sub FormClick_MouseMove(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.MouseMove

TextBox3.Text = Form1.MousePosition.X

TextBox4.Text = Form1.MousePosition.Y

End Sub
 
Hi adriano,

I dont know how the IDE got it bungled , but the second argument should be
MouseEventArgs not EventArgs ... so your code should look like this

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

' You can use e.x here as this will have the coordinates as well and do type
cast
TextBox3.Text = e.x
TextBox4.Text = e.y

End Sub

Hope this helps.
rawCoder
 
Back
Top