vb.net dynamically add, name, place and resize text boxes to a windows form

Hi Experts - I am trying to create a form that will add texboxes to a form.  Just to figure it out, I have created a simple form with one button and one text box.  User enters a number in the text box and it shoud create that number of textboxes. I don't know if I am going about this the wrong way, but here is what I have so far - Also is there a way to dictate the size and  position  -(by the way, I am a newbie)
Thanks
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim I As Integer
        MsgBox(txtNumber.Text)
        For I = 1 To txtNumber.Text
            Dim myTextBox = New TextBox
            myTextBox.Name = "txtDynamic" & I
            myTextBox.Text = "Control Number:" & I
            Me.Controls.Add(myTextBox)
        Next
 
 
    End Sub

Open in new window

NCSA SCADAAsked:
Who is Participating?
 
Jorge PaulinoIT Pro/DeveloperCommented:
You can use also SetBound()
Ex.

        For I As Byte = 1 To 5
            Dim myTextBox As New TextBox
            myTextBox.Name = "txtDynamic" & I
            myTextBox.Text = "Control Number:" & I
            myTextBox.SetBounds(10, 20 * I, 120, 20)
            Me.Controls.Add(myTextBox)
        Next

Open in new window

0
 
UnifiedISCommented:
myTextBox.Size = new size(x,y)
myTextBox.Location.X =
myTextBox.Location.Y =
0
 
NCSA SCADAAuthor Commented:
Thanks for the quick response -
I must be missing somthing - I tried this
            myTextBox.Size = New Size(10, 10)
            myTextBox.Location.X = "485"
            myTextBox.Location.Y = "339"
I get this error - "Expression is a value and therefore cannot be the target of an assignment
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Here you have some extra information
http://msdn.microsoft.com/en-us/library/z0tayb1b.aspx 
0
 
NCSA SCADAAuthor Commented:
That worked perfect - thanks for the additional info as well - cleared it right up
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.