|
-
Jul 5th, 2000, 07:40 PM
#1
Thread Starter
Hyperactive Member
Hi Everyone!
How can I tell if the cursor is in this box?
Line (x1, y1)-(x2, y2), , B
Thanks,
Joey O
-
Jul 5th, 2000, 08:08 PM
#2
Lively Member
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
-
Jul 5th, 2000, 08:25 PM
#3
Frenzied Member
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.
-
Jul 5th, 2000, 08:43 PM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|