Option Explicit
Public WithEvents TxtBox As MSForms.TextBox
Public BackColor As Long
Private Sub Class_Initialize()
BackColor = RGB(255, 255, 255)
End Sub
Private Sub Class_Terminate()
Set TxtBox = Nothing
End Sub
Private Sub TxtBox_Change()
TxtBox.BackColor = BackColor
End Sub
Pojmenuj ho třeba clsTextBox.
Kód v UserForm1 oprav:
Dim TB As New clsTextBox ' Kontejner s dynamickým TextBoxem
Private Sub UserForm_Activate()
Set TB = New clsTextBox
Set TB.TxtBox = Me.Controls.Add("Forms.TextBox.1")
With TB.TxtBox
.Name = "TextBox1"
.Top = 10
.Left = 10
.Width = 200
.Height = 14
.Value = "Text"
.Font.Size = 8
End With
TB.BackColor = RGB(20, 20, 20)
End Sub
Private Sub TextBox2_Change()
TextBox2.BackColor = RGB(105, 125, 205)
End Sub
citovat