本文介绍了MouseMove-什么是反向事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub framePDF_MouseMove(ByVal... )
framePDF.BackColor = &H80000012&

因此,框架的颜色正在改变.
我找不到返回光标颜色的事件-当光标离开框架时?

So, the frame's color is changing.
I can't find the event to return the color back - when the cursor is away from the frame ?

推荐答案

在vba和VB6中,没有MouseLeave事件.

In vba and VB6 there is no MouseLeave event.

实现此目的的最佳方法是在鼠标进入框架时启动计时器.

The best way to achieve this is to start a timer when the mouse enters the frame.

然后在计时器代码中检查鼠标指针是否仍在框架的边界内.如果没有改变颜色并停止计时器

Then in the timer code check to see if the mouse pointer is still within the bounds of the frame. If not change the colour back and stop the timer

将此代码放在模块中:

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

Create a timer on your form, set interval =10 Enbaled = False

然后代码看起来像这样:

Then the code looks something like this:

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-什么是反向事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 15:20