16 automatisch erzeugte Label format ändern?
24.08.2003 18:16:43
GraFri
Habe in einer Userform mittels Code (Klassenmodul) zur Laufzeit 16 Label erzeugt. Diese 16 Label würde ich gerne auch mittels Code anders formatieren (Hintergrundfarbe). Komme aber nicht dahinter.
Hier der Code:
'------------------------------------------------------------------
'Code der Userform 'Userform1'
Option Explicit
Private oControlArray(16) As clsLabel
Dim n As Long
Dim Spalte As Long
Dim Zeile As Long
UserForm_Initialize() Dim cnt As CommandBarControl Dim neuLabel As Control '16 Label erzeugen und anordnen so formatieren Spalte = 0: Zeile = 0 For n = 1 To 16 Set neuLabel = Me.Controls.Add("Forms.Label.1") 'Label formatieren und positionieren With neuLabel .Height = 20: .Width = 16 'Position .Left = 12 + .Width * Spalte: .Top = 70 + .Height * Zeile .BackColor = &HC0FFFF Spalte = Spalte + 1 If Spalte = 4 Then Spalte = 0 Zeile = Zeile + 1 End If 'Formatierung Font = "Arial": .Font.Size = 12 .Visible = True .Caption = n End With Set oControlArray(n) = New clsLabel oControlArray(n).Initialise neuLabel, n Next Set neuLabel = Nothing End SubPrivate Sub
'Die Hintergrundfarbe aller Label soll sich ändern
cmdÄndern_Click() ' ??? ' ??? End SubPrivate Sub
'
'------------------------------------------------------------------
'
'In einem Klasenmodul 'clsLabel'
Option Explicit
Option Compare Text
Private WithEvents zoLabel As MSForms.Label
Private zlIndex As Long
Dim oControl
Class_Terminate() Set zoLabel = Nothing End SubPrivate Sub
Sub Initialise(oControl As Object, lControlIndex As Long)
zlIndex = lControlIndex
Select Case TypeName(oControl)
Case "Label"
Set zoLabel = oControl
Case Else
Stop 'Unregistrierter Type!
End Select
End Sub
Property Get Index() As Long
Index = zlIndex
End Property
'
'------------------------------------------------------------------
Code eingefügt mit Syntaxhighlighter 2.4
Vielleicht kann mir jemand helfen. Besten Dank.
Datei: https://www.herber.de/bbs/user/695.xls
mfg, GraFri