Hello

I am struggling with something quite elementary and simple. I am creating 200 dynamic textboxes with the following code :
Code:
    Private Sub AddTxtBoxes()
        Dim I As Integer
        Dim txtHeight As Integer
        Dim txtWidth As Integer

        Dim txt As New TextBox
        txtHeight = 10
        txtWidth = 10

        txt.Name = "TextBox1"
        txt.Text = ""
        txt.Location = New Point(txtWidth, txtHeight)
        txt.Multiline = False
        txt.MaxLength = 5

        Me.Panel1.Controls.Add(txt)

        For I = 2 To 200
            Dim txt2 As New TextBox
            txtHeight += 30
            txt2.Name = "TextBox" & I
            txt2.Text = ""
            txt2.Location = New Point(txtWidth, txtHeight)
            txt.Multiline = False
            txt.MaxLength = 5

            Select Case I

                Case 21, 41, 61, 81, 101, 121, 141, 161, 181
                    txtHeight = 10
                    txtWidth += 110
                    txt2.Location = New Point(txtWidth, txtHeight)
            End Select

            Me.Panel1.Controls.Add(txt2)
        Next I

    End Sub
Now, I need to restrict the user to type a maximum of 5 characters inside. The MaxLength property is supposed to help me with that, but the user is still allowed to type more than five characters!

can anyone help?

Later on, after I have crossed this bridge, I'll need to allow a minimum of five as well - so that the user will always be able to enter only five characters inside each textbox. Another problem in the future will be to allow only numeric digits. These are product codes, whic are always numeric, and always 5 characters in length