Post by Greg HindI am trying to add a Label control programatically to a form. I am trying
to create an appilcation in Microsoft Visuals Basic 6.0 and am seeking help.
In addition to Ralph's comments you do this. Note that you can
either use add array elements to an existing (design time) control array
or use the method below, but you can't do both (i. e. dynamically
create a control array)
Option Explicit
Private WithEvents lblObject As Label
Private Sub Form_Load()
Set lblObject = Form1.Controls.Add("VB.Label", "lblOne")
With lblObject
.Visible = True
.Caption = "Dynamic Label"
.Move (Width - .Width) \ 2, (Height - .Height) \ 2
End With
End Sub
Private Sub lblObject_Click()
MsgBox "This is a dynamically added control"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set lblObject = Nothing
End Sub