je sais pas, mais ca marche en passant pas des classes :
creer une classe Cls_Label
Option Explicit
Private WithEvents oLed As VB.Label 'on peut recréer les évènements du composant Public Event Click()
Public Sub Create(oForm As Form, sKey As String) Set oLed = oForm.Controls.Add("VB.label", sKey) End Sub
Private Sub Class_Terminate() Set oLed = Nothing End Sub
Private Sub oLed_Click() 'ICI LE CODE DU CLICK
RaiseEvent Click 'lie l'événement vb.Label_Click à Label_Click End Sub
'Il faut recréer les propriété et méthode du composant '===================================================== Public Property Let Top(sNewValue As Single) oLed.Top = sNewValue End Property
Public Property Get Top() As Single Top = oLed.Top End Property
Public Property Let Left(sNewValue As Single) oLed.Left = sNewValue End Property
Public Property Get Left() As Single Left = oLed.Left End Property
Public Property Let Height(sNewValue As Single) oLed.Height = sNewValue End Property
Public Property Get Height() As Single Height = oLed.Height End Property
Public Property Let Width(sNewValue As Single) oLed.Width = sNewValue End Property
Public Property Get Width() As Single Width = oLed.Width End Property
Public Property Let BorderStyle(iNewValue As Integer) oLed.BorderStyle = iNewValue End Property
Public Property Get BorderStyle() As Integer BorderStyle = oLed.BorderStyle End Property
Public Property Let Visible(bNewValue As Boolean) oLed.Visible = bNewValue End Property
Public Property Get Visible() As Boolean Visible = oLed.Visible End Property
Public Property Let BackColor(lNewValue As Long) oLed.BackColor = lNewValue End Property
Public Property Get BackColor() As Long BackColor = oLed.BackColor End Property
Public Property Let Appearance(lNewValue As Long) oLed.Appearance = lNewValue End Property
Public Property Get Appearance() As Long Appearance = oLed.Appearance End Property
Public Property Let Caption(lNewValue As String) oLed.Caption = lNewValue End Property
Public Property Get Caption() As String Caption = oLed.Caption End Property
Public Property Let Alignment(lNewValue As Long) oLed.Alignment = lNewValue End Property
Public Property Get Alignment() As Long Alignment = oLed.Alignment End Property
Public Property Let Bold(lNewValue As Boolean) oLed.Font.Bold = lNewValue End Property
Public Property Get Bold() As Boolean Bold = oLed.Font.Bold End Property
Public Property Let Tag(lNewValue As Boolean) oLed.Tag = lNewValue End Property
Public Property Get Tag() As Boolean Tag = oLed.Tag End Property
|
puis creer une classe cls_labels
Option Explicit
Private cCol As Collection
Public Function Add(oForm As Form, sKey As String) As Cls_Label Dim oLed As New Cls_Label oLed.Create oForm, sKey cCol.Add oLed 'renvoyer l'objet créé Set Add = oLed End Function
Public Property Get Item(vIndexKey As Variant) As Cls_Label 'vIndexKey contient l'index ou la clé dans la collection Set Item = cCol(vIndexKey) End Property
Public Property Get Count() As Long Count = cCol.Count End Property
Public Sub Remove(vIndexKey As Variant) 'vIndexKey contient l'index ou la clé, il est donc cCol.Remove vIndexKey End Sub
Public Property Get NewEnum() As IUnknown 'permet d'énumérer la collection avec la syntaxe For...Each Set NewEnum = cCol.[_NewEnum] End Property
Private Sub Class_Initialize() Set cCol = New Collection End Sub
Private Sub Class_Terminate() Set cCol = Nothing End Sub
|
et apres s'utilise comme ca :
For I = 0 To 10 Set oLed = cLeds.Add("Label" & I) ' création du contrôle avec un nom unique oLed.Caption = I 'paramétrage du contrôle créé oLed.Top = 1400 + (I - 1) * 480
oLed.Height = 495 oLed.Width = 495 oLed.BorderStyle = 1 oLed.Visible = True oLed.BackColor = vbWhite oLed.Appearance = 0 oLed.Alignment = 2 oLed.Tag = 0 Next I
|
Bon courage
@++

BasicInstinct
