Results 1 to 6 of 6

Thread: Mouse position

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Unhappy

    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.

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    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.

  3. #3
    Lively Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    97

    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...

    Anil

  4. #4
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  5. #5
    Guest
    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

  6. #6

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Wink 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
  •  



Click Here to Expand Forum to Full Width