|
-
Nov 8th, 2000, 11:17 AM
#1
Thread Starter
Fanatic Member
Should be a simple question but does anybody know how to find the x and y coordinates of the mouse (in terms of the screen) at any given time?
I just can't work it out for the life of me and a moments assistance from anybody to point me in the right direction would be much appreciated.
Simon.
-
Nov 8th, 2000, 11:28 AM
#2
Fanatic Member
If you are needing the coordinates on a form within VB, the following will show that.
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Caption = X
Label2.Caption = Y
End Sub
If you need the coordinates for the whole screen, I am sure someone else will post code for that.
-
Nov 8th, 2000, 11:35 AM
#3
Lively Member
It is simple....
Just go to form_MouseMove Event and there you will find the X and Y coordinates.This will give the mouse position on a form
Here is an Example
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = "X" & X & " " & " Y " & Y
End Sub
This Example will display the X and Y corodinates, on the form's caption,of the mouse on a form
I think this is what you want...
-
Nov 8th, 2000, 11:43 AM
#4
Hyperactive Member
Any where on the screen...
Public Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 8th, 2000, 03:33 PM
#5
Here is an example of the usage of GetCursorPos. Add the following to a form with a CommandButton.
Code:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Command1_Click()
Dim PT As POINTAPI
GetCursorPos PT
MsgBox "(" & PT.x & "," & PT.y & ")"
End Sub
-
Nov 9th, 2000, 03:56 AM
#6
Thread Starter
Fanatic Member
Thanks
I appreciate all those who offered help.
What I was actually able to use was the API as I had to know the screen mouse position outside of a mouse move event.
Thanks again,
Simon.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|