Results 1 to 4 of 4

Thread: Cursor Position

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Hi Everyone!

    How can I tell if the cursor is in this box?

    Line (x1, y1)-(x2, y2), , B

    Thanks,
    Joey O


  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    82
    hi,
    you can know by the folowing statements:

    if X >x1 and X<x2 then
    if Y >y1 and Y<y2 then
    statements if the cursor is in the box
    end if
    end if

    these statements must be in one of the events which give a X,Y coordinates of the cursor (like Form1_MouseMove)
    bye, hope i helped

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    add a new module to your project and slap this in it

    Code:
    Option Explicit
    
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    
    
    Public Function IsCursorInBox(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single, Window As Object)
    
    Dim apiPos As POINTAPI
    Dim x As Single
    Dim y As Single
    Dim retval As Boolean
    
    On Error GoTo ERR_IsCursorInBox:
    
    GetCursorPos apiPos
    
    ScreenToClient Window.hwnd, apiPos
    
    x = Window.ScaleX(apiPos.x, Window.ScaleMode, vbPixels)
    y = Window.ScaleY(apiPos.y, Window.ScaleMode, vbPixels)
    
    retval = x > x1
    retval = retval And x < x2
    retval = retval And y > y1
    retval = retval And y < y2
    
    IsCursorInBox = retval
    
    Exit Function
    
    ERR_IsCursorInBox:
    
    Err.Raise 13
    
    End Function
    Window is the window that the coordinates are based in, for example if the coords are relitive to Picture1 then Window would be Picture1.

    It Only works on Forms and Pictureboxes.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Yes,Yes.Yes,

    Thanks ysa1441! it's gonna be great having you around. Thanks for the response.
    Sam thats just what I needed. I'm outside of a command that has x,y params.
    Joey o

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