954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Cursor Position

Hi,
i want to get current position of cursor on the form.
there are label to show the coordinates of cursor position.
anyone can help me. i don't have idea for this.

thanks
Best regards.

Vega_Knight
Light Poster
36 posts since Feb 2008
Reputation Points: 18
Solved Threads: 0
 

Try this, it will return the position on the screen in pixels of the cursor :

Option Explicit
Private Type POINTAPI
    X As Long
    Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Function GetXCursorPos() As Long
   Dim pt As POINTAPI
   GetCursorPos pt
   GetXCursorPos = pt.X
End Function

Public Function GetYCursorPos() As Long
   Dim pt As POINTAPI
   GetCursorPos pt
   GetYCursorPos = pt.Y
End Function

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label1.Caption = "X Screen Position = " & GetXCursorPos
    Label2.Caption = "Y Screen Position =  " & GetYCursorPos
End Sub


Hope it helps.

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

Great..it run like a charm..

Vega_Knight
Light Poster
36 posts since Feb 2008
Reputation Points: 18
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: