Private Sub framePDF_MouseMove(ByVal...)
framePDF.BackColor = &H80000012&
因此,框架的顏色正在改變。
我找不到事件返回顏色 - 當光標離開框架?MouseMove - 什麼是反向事件?
Private Sub framePDF_MouseMove(ByVal...)
framePDF.BackColor = &H80000012&
因此,框架的顏色正在改變。
我找不到事件返回顏色 - 當光標離開框架?MouseMove - 什麼是反向事件?
在vba和VB6中沒有MouseLeave事件。
實現此目的的最佳方法是在鼠標進入框架時啓動計時器。
然後在計時器代碼中檢查鼠標指針是否仍在框架邊界內。如果不改變顏色重新和停止計時器
將這個代碼模塊中:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As _
POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
創建窗體上的計時器,設置interval =10
Enbaled = False
然後代碼看起來是這樣的:
Private Sub frameTest_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
frameTest.BackColor = vbRed
tmrMouseLeave.Enabled = True
End Sub
Private Sub tmrMouseLeave_Timer()
Dim pt As POINTAPI
Call GetCursorPos(pt)
Dim xValue As Long, yValue As Long
xValue = pt.x * Screen.TwipsPerPixelX
yValue = pt.y * Screen.TwipsPerPixelY
If (xValue > (Me.Left + frameTest.Left)) And _
(xValue < (Me.Left + frameTest.Left + frameTest.width)) And _
(yValue > (Me.Top + frameTest.Top)) And _
(yValue < (Me.Top + frameTest.Top + frameTest.height)) Then
'we are still inside the frame
Else
'mouse is outside the frame
frameTest.BackColor = vbBlue
tmrMouseLeave.Enabled = False
End If
End Sub
在用戶窗體上?用戶窗體也有一個MouseMove事件,當您在Frame中時不會觸發。
Private Sub Frame1_MouseMove(ByVal ...)
Me.Frame1.BackColor = vbRed
End Sub
Private Sub UserForm_MouseMove(ByVal ...)
Me.Frame1.BackColor = vbWhite
End Sub
當你結束時會將框架變成紅色,當你不在時變成白色。這些事件不斷髮生,所以明智地使用它們。
迪克,非常好,非常感謝 – Alegro
更簡單的方法:在您的MouseMove事件中,根據控件的寬度和高度(減去邊距,比如5)測試X和Y參數 - 如果鼠標位於邊距內,則將其視爲「鼠標移出」並更改控件的顏色相應。無需併發按鈕,z順序操作,框架等
是否有可能增加大於標籤稍大的框架,它的位置在標籤後面和MouseMove事件添加到框架?然後,您可以檢測並查詢標籤顏色,以確定鼠標是否正在離開或輸入標籤。 – user3357963
我想,我明白了。請嘗試,謝謝 – Alegro