Solved dynamically add, name, place and resize text boxes to a windows form

Posted on 2009-04-21
Last Modified: 2013-11-26
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)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim I As Integer


        For I = 1 To txtNumber.Text

            Dim myTextBox = New TextBox

            myTextBox.Name = "txtDynamic" & I

            myTextBox.Text = "Control Number:" & I



    End Sub

Open in new window

Question by:NCSA SCADA
    LVL 18

    Expert Comment

    myTextBox.Size = new size(x,y)
    myTextBox.Location.X =
    myTextBox.Location.Y =

    Author Comment

    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
    LVL 48

    Accepted Solution

    You can use also SetBound()

            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)

    Open in new window

    LVL 48

    Expert Comment

    Here you have some extra information

    Author Closing Comment

    That worked perfect - thanks for the additional info as well - cleared it right up

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now