how do you create a new instance of a control that is already on a form.
I have a control on a form and need to make a few of them but don't know how many i will need to until form is built.
thanks
Printable View
how do you create a new instance of a control that is already on a form.
I have a control on a form and need to make a few of them but don't know how many i will need to until form is built.
thanks
Give the first control (already on the form) an index of 0, which will tell VB to use it as a control array. Then, just use the Load command to make a new one:
Although the new control will be in exactly the same place as the original, so you'd need to move it using code.Code:Load Text1(1)
Text1(1).Visible = True
Don't forget to move it once you create it.
Code:Load Picture1(1)
Picture1(1).Move 0, 0
Picture1(1).Visible = True
'load an array of controls at runtime
'add 3 controls and line them up
'as above create the array and leave only one
'control on the form index(0)
[code]
Private Sub Command1_Click(Index As Integer)
Dim intcre As Integer
Do Until intcre = 3
intcre = intcre + 1
Load Command1(intcre)
Command1(intcre).Left = Command1(intcre - 1).Left + Command1(intcre).Width
Command1(intcre).Top = Command1(intcre - 1).Top
Command1(intcre).Visible = True
Loop
End Sub
[/code}