我希望在鼠标仍处于运行状态时检测到Form上任何Frame上有mouse_down的时间。我知道如何为Click做这件事,但我想在mouse_up之前抓住它。
由于
答案 0 :(得分:2)
您可以为表单上的每个帧创建一个_MouseDown
事件处理程序,或者如果您有多个框架,则可以创建一个通用事件处理程序类
创建一个类模块(例如名为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
为您的Frames声明一个集合
Dim mcolFrames As New Collection
在表单初始化中包含此代码
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
现在,Frme_MouseDown
将在表单上的任何Frame上的MouseDown上执行。使用Frme