I know how to create textbox dynamically but the problem now is that I want it below my previous created textbox

 Dim textbox1 As New TextBox
    textbox1.Name = "Textbox1"
    textbox1.Bounds = New Rectangle(e.Location, New Size(100, 100))

    Me.Controls.Add(textbox1)

Recommended Answers

All 5 Replies

Try this:

Dim textbox1 As New TextBox
textbox1.name = "TextBox1"
textbox1.bounds = New Rectangle(e.Location,New Size(100,100))
textbox1.location.x = myOtherTextBox.Location.x + 40
textbox1.location.y = myOtherTextBox.Location.y
Me.Controls.Add(textbox1)

What is myOtherTextbox because Im getting some error. It was not declared..

     textbox1.Location.X = myOtherTextBox.Location.x + 40
    textbox1.Location.Y = myOtherTextBox.Location.y

Substitute the name for the textbox that you want the new textbox to be placed under.

And the code is wrong, I just noticed.

Correct would be:

textbox1.Location.Y = myOtherTextBox.Location.Y + 40 'You will have to play with this value to adjust it to where you want it.
textbox1.Location.X = myOtherTextBox.Location.X

I know how to create textbox dynamically but the problem now is that I want it below my previous created textbox

I really dont get what you would like to do.
Please re-define it.
thx

I usually keep track of dynamic controls in an array or a collection of some sort. For example

 Private textboxes As New Dictionary(Of Integer,TextBox)
 .
 .
 .
 Dim tb As New TextBox
 tb.Text = "some text"
 .
 .
 .
 textboxes(textboxes.Count) = tb

then you can refer to a specific control as

textboxes(i).Text

If you prefer names over ID numbers then use Dictionary(Of String, TextBox)

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.