Public Class ControlArray
Inherits System.Collections.CollectionBase
Private ReadOnly HostForm As System.Windows.Forms.Form
Public Function AddNewControl(ByVal type As String) As Object
Dim oNewControl As New Object
Dim oNewLabel As New System.Windows.Forms.Label
Dim oNewButton As New System.Windows.Forms.Button
Dim oNewTextbox As New System.Windows.Forms.TextBox
Dim oNewCheckbox As New System.Windows.Forms.CheckBox
Dim oNewCombobox As New System.Windows.Forms.ComboBox
Select Case type
Case "label"
Me.List.Add(oNewLabel)
HostForm.Controls.Add(oNewLabel)
oNewLabel.Tag = Me.Count
oNewControl = oNewLabel
Case "button"
Me.List.Add(oNewButton)
HostForm.Controls.Add(oNewButton)
oNewButton.Tag = Me.Count
oNewControl = oNewButton
Case "textbox"
Me.List.Add(oNewTextbox)
HostForm.Controls.Add(oNewTextbox)
oNewTextbox.Tag = Me.Count
oNewControl = oNewTextbox
Case "checkbox"
Me.List.Add(oNewCheckbox)
HostForm.Controls.Add(oNewCheckbox)
oNewCheckbox.Tag = Me.Count
oNewControl = oNewCheckbox
Case "combobox"
Me.List.Add(oNewCombobox)
HostForm.Controls.Add(oNewCombobox)
oNewCombobox.Tag = Me.Count
oNewControl = oNewCombobox
End Select
Return oNewControl
End Function
Public Sub New(ByVal host As System.Windows.Forms.Form)
HostForm = host
'Me.AddNewControl("")
End Sub
Default Public ReadOnly Property Item(ByVal Index As Integer) As System.Object
Get
Return CType(Me.List.Item(Index), System.Object)
End Get
End Property
Public Sub Remove()
' Check to be sure there is a Label to remove.
If Me.Count > 0 Then
' Remove the last Label added to the array
' from the host form controls collection.
' Note the use of the default property in
' accessing the array.
HostForm.Controls.Remove(Me(Me.Count - 1))
Me.List.RemoveAt(Me.Count - 1)
End If
End Sub
End Class