请高手帮忙,对鼠标进行感知编程
我想让窗体上的文本框能对鼠标进行感知,当鼠标移进文本框范围时,背景变红;当鼠标移出文本框范围时,背景色回复。
下面是我写的代码,效果不准确,文本框左半部分能感知,右半部分不能感知,更糟糕的是文本框外左上边缘部分能感知,天啊,我崩溃了,请高手帮帮忙,多谢!
'对象:text1,timer1
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
Dim x1 As Long, y1 As Long, x2 As Long, y2 As Long
Private Sub Form_Load()
x1 = Text1.left
y1 = Text1.top
x2 = x1 + Text1.width
y2 = y1 + Text1.height
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Dim nP As PointAPI
GetCursorPos nP
ScreenToClient Form1.hwnd, nP
Text1.Text = nP.X & Space(2) & nP.Y
If nP.X >= x1 And nP.X <= x2 And nP.Y >= y1 And nP.Y <= y2 Then
Text1.BackColor = vbRed
Else
Text1.BackColor = vbWhite
End If
End Sub
[解决办法]
用mousemove 和mouseleave就行了
[解决办法]
好像走弯路了,VB6的控件有mousemove属性