In a program I’m writing, I need the position of the mouse absolute to the left upper corner of the form.
I’m using this code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "x: " & X & " - y: " & Y
End Sub
When I use this code, the upper left corner has coordinates 0,0. But the problem is that the values are 15 times too big when I move inside the form.
So that’s why I used:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "x: " & X / 15 & " - y: " & Y / 15
End Sub
This gives the correct coordinates, but why do I need to devide this by 15?
I’m not sure if this code will be compatible on other systems.
Looking at the documentation for MouseMove. The X and Y values returned correspond to the “ScaleHeight, ScaleWidth, ScaleLeft, and ScaleTop properties of the object.”
Therefore looking at the documentation for ScaleHeight, ScaleWidth and for ScaleLeft, ScaleTop, it is clear that you can dictate how the X and Y coordinates are determined. You are not limited to Twips or Pixels, but can use whatever numbering system you dictate.
Here’s a quote from the ScaleHeight, ScaleWidth page:
In this regard to assure your results match your expectation, you can tell the form exactly how many user-defined units it contains.