Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to use a simple code in VB6 to extract the mouse coordinates on a Picturebox using MouseMove event and showing these values in a Textbox, but the results obtained are wrong.

Picturebox (Picture1) is ScaleMode = Pixel, Scaleheight = 249, Scalewidth = 305, ScaleLeft = 0, ScaleTop = 0, Height = 3735, Width = 4574, Borderstyle = None, Appareance = Flat.

When mouse is all over to left, X value is 1 and this is wrong because ScaleLeft = 0.
When mouse is all over to right, X value is 303 and this is wrong because ScaleWidth = 305.

When mouse is at top of picturebox, Y value is 1 and this is wrong because ScaleTop = 0.
When mouse is at bottom of picturebox, Y value is 247 and this is wrong because ScaleHeight = 249.

If I set ScaleLeft and ScaleTop to 0 at Form_Load event, the results are different but not correct...

What I'm doing wrong? there's an API to do that in a better way or more accurate?

What I have tried:

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = "X:" & X & "," & "Y:" & Y
End Sub
Posted
Updated 7-Jan-18 9:37am
v2
Comments
Maciej Los 7-Jan-18 15:07pm    
VB6 or VB.NET? This makes the difference!
MaxTTT 7-Jan-18 15:36pm    
VB6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900