Option Explicit
Public WithEvents drpb As msforms.Label 'event du faux dropbutton
Public WithEvents ItemX As msforms.Label 'event des item dans la frame
Public WithEvents formX As UserForm 'event du userform
Public uf As Object 'object userform en variable object ne gère pas les events
Public framm As Object 'object frame en variable object ne gère pas les events
Public comBB As Object 'object combobox en variable object ne gère pas les events
Public fait As Boolean 'on le fait qu'une fois
Dim cl(0 To 100) As New ComBoTransform 'array des instance de classe(la fleme de faire un redim preserve )
Public Function transforme(comb As Object, uf)
Dim i&, Fram, It, dropbutton, pict As IPicture
If Me.fait Then Exit Function
fait = True
Set Fram = uf.Controls.Add("Forms.Frame.1", "fond") 'ajoute la frame
Set dropbutton = uf.Controls.Add("Forms.Label.1", "dropbutton") 'ajoute le faux dropbutton
comb.ShowDropButtonWhen = 0 'on masque le vrai dropbutton
With dropbutton 'avec le faux dropbutton
.Height = comb.Height - 1
.Width = 13
.Font.Name = "Wingdings 3"
DoEvents
.Caption = "q"
.Font.Bold = True
.Left = comb.Left + comb.Width - .Width - 2
.Top = comb.Top
.TextAlign = 2
.BorderStyle = 1
End With
comb.Width = comb.Width - 15 'on enleve le width du dropbutton a la comboboxsinon elle masquera toujours le label
With Fram 'properties frames
.Width = comb.Width + 15
.Left = comb.Left
.Height = comb.ListRows * 13
.Top = comb.Top + comb.Height
.ScrollBars = 2
.Visible = False
.BorderStyle = 1
For i = 0 To comb.ListCount - 1 'boucle sur les item de la combo
With cl(i) 'ajoute chaque element dans chaque instance de classe
Set .drpb = dropbutton 'gère un event
Set .uf = uf 'ne gère pas d'évent
Set .framm = Fram 'ne gère pas d'évent
Set .comBB = comb 'ne gère pas d'évent
Set .formX = uf ' gère d'évent
End With
Set It = .Controls.Add("Forms.Label.1", "It" & i)
With It
.Caption = comb.List(i)
.Width = Fram.Width
.Height = 13
.BorderStyle = 0
.BackColor = Array(vbGreen, vbYellow)(Abs(i Mod 2 = 0))
.Top = 15 * i
.Left = 2
.Font.Name = "verdana"
End With
Set cl(i).ItemX = It 'gère un event
Next
.ScrollHeight = comb.ListCount * (It.Height + 2)
End With
End Function
'LES EVENTS
Private Sub formX_Click(): framm.Visible = False: End Sub
Private Sub drpb_Click(): framm.Visible = True: framm.ScrollTop = 0: End Sub
Private Sub ItemX_Click(): comBB.Value = ItemX.Caption: framm.Visible = False: End Sub