如何在鼠标仍然停止时检测Userform框架上的mouse_down [英] How to detect a mouse_down on a Userform Frame while the mouse is still down

查看:283
本文介绍了如何在鼠标仍然停止时检测Userform框架上的mouse_down的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当鼠标仍然停止时,我想检测窗体上任何框架上是否有一个mouse_down。我知道如何做一个点击,但我想在mouse_up之前抓住它。



谢谢

解决方案

您可以为表单上的每个框架创建一个 _MouseDown 事件处理程序,或者如果您有多个框架,则可以创建一个通用事件处理程序类



创建一个类模块(例如命名为 cUserFormEvents



公开WithEvents Frme As MSForms.frame
公共frm As UserForm

私有子Frme_MouseDown(_
ByVal Button As Integer,_
ByVal Shift As Integer,_
ByVal X As Single,_
ByVal Y As Single)

'将您的事件代码放在
MsgBox Frme。 Caption

End Sub

声明您的框架的集合

  Dim mcolFrames As New Collection 

在您的表单初始化中包含此代码

  Private Sub UserForm_Initialize() 
Dim ctl As MSForms.Control
Dim clsEvents As cUserFormEvents

'循环通过userform
上的所有控件对于每个ctl在Me.Controls
'只进程帧
如果TypeOf ctl是MSForms.frame然后
'实例化类模块并分配属性
设置clsEvents =新的cUserFormEvents
设置clsEvents.Frme = ctl
设置clsEvents .frm = Me

'添加实例到集合
mcolFrames.Add clsEvents

如果

下一个ctl

End Sub

现在, Frme_MouseDown 将在表单上的任何框架上的MouseDown上执行。使用 Frme


访问特定的框架

I want to detect when there's a mouse_down on any Frame on the Form while the mouse is still down. I know how to do it for a Click, but I want to catch it before mouse_up.

Thanks

解决方案

You can create a _MouseDown event handler for each frame on the form, or if you have many frames you can create a generic event handler class

Create a Class module (eg named cUserFormEvents)

Public WithEvents Frme As MSForms.frame
Public frm As UserForm

Private Sub Frme_MouseDown( _
 ByVal Button As Integer, _
 ByVal Shift As Integer, _
 ByVal X As Single, _
 ByVal Y As Single)

    ' Put your event code here
    MsgBox Frme.Caption

End Sub

Declare a collection for your Frames

Dim mcolFrames As New Collection

Include this code in your form initialistion

Private Sub UserForm_Initialize()
    Dim ctl As MSForms.Control
    Dim clsEvents As cUserFormEvents

    'Loop through all controls on userform
    For Each ctl In Me.Controls
        'Only process Frames
        If TypeOf ctl Is MSForms.frame Then
            'Instantiate class module and assign properties
            Set clsEvents = New cUserFormEvents
            Set clsEvents.Frme = ctl
            Set clsEvents.frm = Me

            'Add instance to collection
            mcolFrames.Add clsEvents

        End If

    Next ctl

End Sub

Now, Frme_MouseDown will execute on MouseDown on any Frame on the form. Access the specific Frame with Frme

这篇关于如何在鼠标仍然停止时检测Userform框架上的mouse_down的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆