我想在鼠标仍然按下时检测窗体上的任何框架上何时有 mouse_down。我知道如何点击,但我想在 mouse_up 之前抓住它。
谢谢
您可以_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