[VB6] How to get the mouse cursor position in a form
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [VB6] How to get the mouse cursor position in a form

  1. #1
    Join Date
    Dec 2002
    Location
    Hong Kong
    Posts
    2

    [VB6] How to get the mouse cursor position in a form

    I am a newbie on VB and I would like to write a PhotoHunt game in VB6.0. When player click on the image in the VB form, the program should be able to detect the coordinate of the mouse cursor with respect to the image (i.e. with the upper left coner of the image as the origin)

    I know there is a function called GetCursorPos to retrieve the mouse cursor's coordinate. But that coordinates is w.r.t. the whole screen. So,
    1)is there another function for getting the cursor's coordinate w.r.t. the image in the form? Or
    2)are there functions for getting the form's coordinate and the image's coordinate w.r.t the whole screen?

    Thx~

  2. #2
    Join Date
    Dec 2002
    Posts
    5
    Im not sure what you meen by the coords of the image, but if you want to get the x and y of the mouse on a form, just put this code in Form_MouseMove

    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
    This will print the coords into the debug dialog.

    -Manuel

  3. #3
    Join Date
    Dec 2002
    Location
    Hong Kong
    Posts
    2
    oh, it seems I asked a very silly question......I was too concentrated on the mouse_click() event and didtn't notice that the coordinates I wanted was already provided by some other events.........
    Now the MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) event simply solve my problem~ THX~

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center