Private Sub Plus_Btn_Click(sender As Object, e As EventArgs) Handles A_Plus_Btn.Click, C_Txb.Click
    Dim Txb As TextBox
    If x < MAX Then
        x += 1
    Else
        x = 5
    End If

    For i As Integer = 1 To x
        For j As Integer = 1 To x
            Txb = New TextBox
            Txb.Size = New Drawing.Size(100, 20)
            Txb.Location = New Point(10 + 100 * i, 10 + 25 * j)
            Txb.Name = "Txb" & i & "," & j

            AddHandler Txb.TextChanged, AddressOf TextBox_TextChanged
            boxes(i) = Txb
            Me.Controls.Add(Txb)
        Next
    Next
End Sub

Private Sub TextBox_TextChanged(sender As Object, e As EventArgs)
Dim box As TextBox = DirectCast(sender, TextBox)
Me.Text = box.Name & ": " & box.Text
End Sub

Private Sub Minus_Btn_Click(sender As Object, e As EventArgs) Handles A_Minus_Btn.Click, C_Txb.Click
    Dim Txb As TextBox
    If x > MIN Then
        x -= 1
    Else
        x = MIN
    End If

    For i As Integer = 1 To x
        For j As Integer = 1 To x
            Txb = New TextBox
            Txb.Size = New Drawing.Size(100, 20)
            Txb.Location = New Point(10 + 100 * i, 10 + 25 * j)
            Txb.Name = "Txb" & i & "," & j

            AddHandler Txb.TextChanged, AddressOf TextBox_TextChanged
            boxes(i) = Txb
            Me.Controls.Add(Txb)
        Next
    Next
End Sub

I want to make TextBox into array and increase/decrease with buttons.

ex) dim x=1 [+] [-]
x = 1:
[]

x = 2:
[][]
[][]

x = 3:
[][][]
[][][]
[][][]
...

But it's made with the code I wrote above, but it doesn't remove.
And it's not array system, it's hard to manage.

I'd rethink this one. Maybe keep the code for the Plus and Minus button to simple x++ and x--- with the range check followed to a call to a new function that destroys the old text box array and display then creates a new text box array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.