判断鼠标停留 Picture控件一种思想Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.BackColor = &HFF0000
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.BackColor = &H0
End Sub
Picture1.BackColor = &HFF0000
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.BackColor = &H0
End Sub
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseOver As Boolean
MouseOver = (0 <= X) And (X <= command2.Width) And (0 <= Y) And (Y <= command2.Height)
If MouseOver Then
' MouseOver Event
command2.Caption = "Over"
SetCapture command2.hWnd
Else
' MouseLeave Event
command2.Caption = "Leave"
ReleaseCapture
End If
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
i = True
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
i = False
End SubPrivate Sub Timer1_Timer()
If i = True Then '鼠标在按钮上
End If
If i = False Then '鼠标不在按钮上
End If
End Sub
'你的窗体一定不止两个控件,只要不是command1的mousemove事件,就将i赋值为false.
直接引用就可以了。
只有对窗体的每个控件编程了!
上面两个 API 什么功能?
SetCapture
ReleaseCapture
Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub PicChangemain(sPic As PictureBox, X As Single, Y As Single)
Dim MouseExit As BooleanMouseExit = (0 <= X) And (X <= sPic.Width) And (0 <= Y) And (Y <= sPic.Height)If MouseExit Then
sPic.Picture = ImageHomesellT.ListImages(Val(sPic.Tag)).Picture
SetCapture sPic.hwndElsesPic.Picture = ImageHomesell.ListImages(Val(sPic.Tag)).Picture
ReleaseCapture
End If
End Sub
这是一个图片按钮移到变化的过程用于MOSEMOVE中看看吧