Hi all
I'm trying to figure out a way for label controls that are created at runtime to trigger a 'MouseMove' event that will make the control's forecolor white and the remaining controls grey.
These controls are created dynamically based on a number of cells within Excel that are populated after a database check, and therefore the amount of labels required cannot be created at design-time.
Just to make you aware, what I DO have working is making my labels fire off the same event when any of them are clicked based on a WithEvents declaration in my custom class.
In total then, so far, I have:
Here's some code:
clsEvents
Userform code
FYI: the 'clsUCP' merely adds the dynamic controls to a separate collection when the 'LoadUCP' procedure / method is called. All of this works which is why I haven't included any code.
The 'dynLBLCollection' is what is adding each instance of the class generated within the For / Next loop, and is allowing me to see the message box prompt shown in 'clsEvents'.
I hope this all makes sense. Any help / advice would be gratefully received!
Thanks
I'm trying to figure out a way for label controls that are created at runtime to trigger a 'MouseMove' event that will make the control's forecolor white and the remaining controls grey.
These controls are created dynamically based on a number of cells within Excel that are populated after a database check, and therefore the amount of labels required cannot be created at design-time.
Just to make you aware, what I DO have working is making my labels fire off the same event when any of them are clicked based on a WithEvents declaration in my custom class.
In total then, so far, I have:
- A class (called clsEvents) containing a 'WithEvents' declaration
- A '_Click' event with a message box prompt to test whether my dynamic labels fire off this message (they do)
- A module level collection in my userform containing instances of my 'clsEvents' instances to keep them in scope.
Here's some code:
clsEvents
Code:
Option Explicit
Public WithEvents hL_LBL As MSForms.Label
Private Sub hL_LBL_Click()
MsgBox "clsEvents button clicked"
End Sub
Private Sub hL_LBL_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'What goes here...?
End Sub
Userform code
Code:
Dim i As Byte
Dim ctrlLBL As MSForms.Label
Dim lblHandler As clsEvents
Dim objUCP
Set objUCP = New clsUCP
Set dynLBLCollection = New Collection
objUCP.LoadUCP
For i = 1 To objUCP.HighlightCollection.count
Set lblHandler = New clsEvents
Set ctrlLBL = objUCP.HighlightCollection(i)
Set lblHandler.hL_LBL = ctrlLBL
dynLBLCollection.Add lblHandler
Next
FYI: the 'clsUCP' merely adds the dynamic controls to a separate collection when the 'LoadUCP' procedure / method is called. All of this works which is why I haven't included any code.
The 'dynLBLCollection' is what is adding each instance of the class generated within the For / Next loop, and is allowing me to see the message box prompt shown in 'clsEvents'.
I hope this all makes sense. Any help / advice would be gratefully received!
Thanks