Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Respected Sir
I am trying to add textbox at runtime. but my problem is textbox is added on same location but i want to add textbox at different location.
So pls help me :confused:
Code that i am using is :
VB
Dim NumberOfControls As Integer = 5
    Dim tbx As Integer = 64
    Dim tby As Integer = 278
    Dim Labelx As Integer = 45
    Dim labely As Integer = 298
    Dim tb As New TextBox()
    Dim lbl As New Label

Public Sub CreateTextBoxes()

        For counter As Integer = 0 To NumberOfControls
            tb.Width = 150
            tb.Height = 18
            lbl.Width = 200
            lbl.Height = 20
            tb.Name = "TextBoxID" & (counter + 1).ToString()
            lbl.Name = "Label" & (counter).ToString
            tb.Text = "Enter Title " & counter
            lbl.Text = "Label" & " " & (counter) & " " & ":".ToString
            tb.Location = New System.Drawing.Point(tbx, tby)
            lbl.Location = New System.Drawing.Point(Labelx, labely)
            tbx = tbx + 10
            tby = tby + 10
            Labelx += 10
            labely += 10
            Me.Controls.Add(tb)
            Me.Controls.Add(lbl)
            NumberOfControls += 1
        Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, 
                    ByVal e As System.EventArgs) Handles Button1.Click
        CreateTextBoxes()
End Sub
Posted
Updated 26-Mar-10 22:19pm
v2

 
Share this answer
 
Set Location property of the control.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900