I wanted to simply on click a button to add those newly created textboxes to an array of textboxes. Starting with those labeled "Address". But I am finding this very difficult. I am able to add those originally on the form into the array very easily. But am unable to add the newly created textboxes into the array.
Here is my code so far below.
Public Class Form1
Dim MyBoxes() As TextBox = {Address, UserName, Password}
Dim Numbox As Integer = 1
Sub CopyLayout(ByVal B As Integer)
'add new row
Dim cr As New UserControl1
cr.Left = 0
cr.Address.Name = "Address" & B
cr.Top = Me.Panel1.Controls.OfType(Of UserControl1).Count * cr.Height + 98
Me.Panel1.Controls.Add(cr)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Numbox = Numbox + 1
Call CopyLayout(Numbox)
ReDim Preserve MyBoxes(Numbox)
MyBoxes(Numbox) = Me.Panel1.Controls.Item("Address" & Numbox)
End Sub
End Class
Extra info:
UserControl1.vb simply contains three textboxes named approapriatly as "Address", "Username" and "Password".