Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Label1.ForeColor = vbBlue End Sub Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Label1.ForeColor = vbRed End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Label1.Caption = "Label1" End SubPrivate Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Label1.Caption = "I love you!" End Sub
to lsftest: Timer控件必竟是耗资源的。而且还很难调试。没特殊必要,最好不用。 什么时情都有极端,你说的情况是可能发生。但这些可忽略的就忽略。 有很多商业软件都这酥做的,不信你看看。 东信达的<企业动力>......
使用mousemove事件和mouseexit事件实现,mouseexit事件(即鼠标移出控件)不是vb内置, 源代码如下: 捕捉 MouseExit 事件 MouseDown、MouseUp、MouseMove。VB 似乎提供了很好的 Mouse 事件。但好象还缺少什么!对!还差 MouseExit(鼠标移出)事件。在 VB 中,我们要捕捉 MouseExit 事件,必须用 API 函数: Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long 然后,我们可以在控件(以 Picture1 为例)的 MouseMove 事件上加上以下代码:With Picture1 'Change this to the name of the control If Button = 0 Then If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then 'Mouse pointer is outside button, so let other controls receive 'mouseevents too: ReleaseCapture ' 放入鼠标离开的代码 Else ' Mouse pointer is over button, so we'll capture it, thus ' we'll receive mouse messages even if the mouse pointer is ' not over the button SetCapture .hwnd' 放入鼠标进入的代码 End If
mouseover事件。在事件里改变字体与颜色
不过不是我说什么,其实标签里更本没发现MOUSEOVER那个属性跟时间
mousemove倒有一个,但不太会用,如果只是简单地改一下FORECOLOR那之后鼠标再怎地那颜色也回不来了呢,不如你具体一点说好吗,把条件也加上。谢谢
Label1.ForeColor = vbBlue
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.ForeColor = vbRed
End Sub
Label1.Caption = "Label1"
End SubPrivate Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Caption = "I love you!"
End Sub
Timer控件必竟是耗资源的。而且还很难调试。没特殊必要,最好不用。
什么时情都有极端,你说的情况是可能发生。但这些可忽略的就忽略。
有很多商业软件都这酥做的,不信你看看。 东信达的<企业动力>......
源代码如下:
捕捉 MouseExit 事件 MouseDown、MouseUp、MouseMove。VB 似乎提供了很好的 Mouse 事件。但好象还缺少什么!对!还差 MouseExit(鼠标移出)事件。在 VB 中,我们要捕捉 MouseExit 事件,必须用 API 函数:
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
然后,我们可以在控件(以 Picture1 为例)的 MouseMove 事件上加上以下代码:With Picture1 'Change this to the name of the control
If Button = 0 Then
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
'Mouse pointer is outside button, so let other controls receive
'mouseevents too:
ReleaseCapture
' 放入鼠标离开的代码
Else
' Mouse pointer is over button, so we'll capture it, thus
' we'll receive mouse messages even if the mouse pointer is
' not over the button
SetCapture .hwnd' 放入鼠标进入的代码
End If