|
我用下面的代码判断鼠标是否在列表框内,一开始可以正常使用,但后来就不行了,不知道是什么原因。本来我做了备份,但是现在备份的那一个数据库也不能正常使用,而其它的功能正常。重新启动电脑也没有用。
调用方法是: if_Mouse_over Listbox
然后根据 Mouse_Over变量的值来判断是否出界。
Option Compare Database
Public Mouse_Over As Boolean
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Public RetValue As Long
Public Sub If_Mouse_Over(ClipObject As ListBox)
Dim CurrentPoint As POINTAPI
If IsNull(ClipObject) Then Exit Sub
Mouse_Over = False
With CurrentPoint
.X = 0
.Y = 0
End With
RetValue = ClientToScreen(ClipObject, CurrentPoint)
If CurrentPoint.X > ClipObject.Left + ClipObject.Width Or CurrentPoint.X < ClipObject.Left Or CurrentPoint.Y < ClipObject.Top Or CurrentPoint.Y > ClipObject.Top + ClipObject.Height Then Mouse_Over = True
End Sub |
|