请问VB里怎样实现 鼠标指针放在按钮上时按钮变颜色?
2个回答
展开全部
vb6没有mouseleave事件,所以你这个功能需要一些API函数辅助实现
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseOver As Boolean
'判断当前鼠标位置是否在Object1上
MouseOver = (0 <= X) And (X <= Command1.Width) And (0 <= Y) And (Y <= Command1.Height)
If MouseOver Then
' MouseOver Event
' 假如鼠标在Object1上, 则利用SetCapture将每一个鼠标事件都传递给Object1
Me.Caption = "0"
SetCapture Command1.hWnd
Else
' MouseLeave Event
' 假如鼠标不在Object1上, 则利用SetCapture释放鼠标捕捉
Me.Caption = "1"
ReleaseCapture
End If
End Sub
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseOver As Boolean
'判断当前鼠标位置是否在Object1上
MouseOver = (0 <= X) And (X <= Command1.Width) And (0 <= Y) And (Y <= Command1.Height)
If MouseOver Then
' MouseOver Event
' 假如鼠标在Object1上, 则利用SetCapture将每一个鼠标事件都传递给Object1
Me.Caption = "0"
SetCapture Command1.hWnd
Else
' MouseLeave Event
' 假如鼠标不在Object1上, 则利用SetCapture释放鼠标捕捉
Me.Caption = "1"
ReleaseCapture
End If
End Sub
追问
请问这两行:
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
放在哪里?我总是运行出错
追答
放在代码最顶上,不要放在任何一个过程里。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询