How to detect a mouse_down on a Userform Frame while the mouse is still down
Question
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
Solution
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow