create new textbox

shingo99

Freshman
Joined
Jul 19, 2004
Messages
31
hi
i wish to create textbox after i press a button
if the user press the button 3 times, 3 textbox will be created
these textbox are new..not invisible or disable
can this be done?
kindly guide me at this
thank you in advance
 
shingo99 said:
hi
i wish to create textbox after i press a button
if the user press the button 3 times, 3 textbox will be created
these textbox are new..not invisible or disable
can this be done?
kindly guide me at this
thank you in advance

You need to add the new textbox to the container control.

i.e.

Code:
Form1.Controls.Add(TextBox1);

Remember to add the events handler to the textbox if you need them.
 
To add a new textbox...

Visual Basic:
        'Create the textbox
        Dim MyNewTextBox As New TextBox
        'Set the location an size properties how you want them
        MyNewTextBox.Size = New Size(100, 22)
        'Set the text if you want
        'Add the textbox to the form
        Me.Controls.Add(MyNewTextBox)
        'If you want to handle events do it like this
        AddHandler MyNewTextBox.TextChanged, AddressOf DynamicTextBox_TextChanged

Easy as pie. Instantiate it, set the properties, add handlers, and add it.

Now, if you want to keep a reference to the textbox so you can access it at any time, you could do this by storing it in a variable of type textbox, in an array, or an arraylist, whatever suits your needs.

Also, a recommendation: because this code uses a generic handler for any textboxes it creates, if there is any specific information about this textbox that you will need to know about it, I personally would store that info in the form of a string in the textboxes .Tag property.
 
Back
Top