Results 1 to 7 of 7

Thread: Retrieving Mouse coordinates in Form? *Resolved*

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Sweden
    Posts
    9

    Retrieving Mouse coordinates in Form? *Resolved*

    Hi,
    I want to set the caption of two labels to the X and Y mouse coordinates when the user presses a command button.
    How do I retrieve them in an expression? I have tested Xmouse and Ymouse but that didn't work.
    Any help will be appreciated



    Man, being a newbie sucks ^_^. But I'll not give up until I'm a pro in VB
    Last edited by mattis86; Sep 30th, 2002 at 02:50 PM.

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    MouseMove Event of Form I believe returns x and y position...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Sweden
    Posts
    9
    But I need to get the values in the Command1_Click() event

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Command1_MouseMove
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. '' Display the co-ordinates of the mouse pointer every 50ms
    2. ''
    3. Private lastTick As Long
    4. Private mouseCords As POINTAPI
    5. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    6. Private Declare Function GetTickCount Lib "kernel32" () As Long
    7.  
    8. Private Type POINTAPI
    9.     x As Long
    10.     y As Long
    11. End Type
    12.  
    13. Private Sub Form_Load()
    14.     Show
    15.     Do
    16.         DoEvents
    17.         If GetTickCount - lastTick > 50 Then
    18.             lastTick = GetTickCount
    19.             GetCursorPos mouseCords
    20.             With mouseCords
    21.                 Debug.Print .x & "," & .y
    22.             End With
    23.         End If
    24.     Loop
    25. End Sub

    You can just iomplement for the Command1_Click...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Sweden
    Posts
    9
    Hey thank you. That worked just fine

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by mattis86
    Hey thank you. That worked just fine
    You are welcome. Add resolved to the subject line of your first thread...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width