[RESOLVED] XY coords from Mouse click
I am working with a PictureBox and trying to click on the picture and OnClick i want to capture XY coord from the cursor.
I am using the following code
Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
Dim X As Long
Dim Y As Long
Text1.Text = Text1.Text & X & " "
Text2.Text = Text2.Text & Y & " "
End Sub
The issue i have is that no matter where i click on the picturebox it returns a 0 for both the X and Y coordinates.
I read something somewhere about seting the Scale to Pixel but that doesnt seem to be working for me.
Any help would be greatly appreciated.
Re: XY coords from Mouse click
Nvm i got it working now.
Ty for looking
Re: XY coords from Mouse click
The problem is: in your code you are not assigning any values to the variables. You simply define them and display them without assigning any values.
vb Code:
Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
Debug.Print(e.X) '~~~ X position
Debug.Print(e.Y) '~~~ Y position
End Sub
If the problem is sorted out, it is better to mark the thread as RESOLVED. In that way, others would be able to know that your problem is sorted out. :wave:
Good luck..:thumb: