2

I'm a beginner in WinForms VB NET programming. I need to create text box at a run time.

I found example in a search engine how to implement this:

Private Sub Command1_Click()
    Dim TextControl As TextBox
    ControlID = ControlID + 1
    Load Text1(ControlID)
    Set TextControl = Text1(ControlID)
    With TextControl
        .Left = (Text1(ControlID - 1).Left + Text1(ControlID - 1).Width) + 10
        .Top = 20
        .Width = 100
        .Height = 20
        .Visible = True
    End With
End Sub

But I have some difficulties with example's code.

Would someone explain the following VB NET code rows?

    Load Text1(ControlID)
    Set TextControl = Text1(ControlID)
    With TextControl
    End With
3
  • Um. Where did you get that from? So far as I'm aware, Load was VB6 (and earlier), and doesn't exist in VB.NET. (The presence of Set is another clue that this might not by VB.NET code) Commented Jun 7, 2012 at 7:31
  • 1
    this is not vb.net code - it is old visual basic code (I think VB 6). Although it looks the same, vb.net is not backwards compatible to VB 6. You want an example in VB 6 or in VB.net? Commented Jun 7, 2012 at 7:32
  • Ando,thank you i need example in VB NET Commented Jun 7, 2012 at 8:51

3 Answers 3

3

You can check the following example that does exactly what you want to:

Private Sub btnCreateTextbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTextbox.Click
    Dim textbox1 As New TextBox
    textbox1.Name = "Textbox1"
    textbox1.Size = New Size(170, 20)
    textbox1.Location = New Point(167, 32)
    GroupBox1.Controls.Add(textbox1)
End Sub

look for reference and good explanation: http://www.authorcode.com/create-dynamic-textbox-and-label-in-vb-net/

Sign up to request clarification or add additional context in comments.

Comments

1

It's VB code.

"Load Text1(ControlID)" It means load Text1(controlID) into memory , Text1(controlID) is a textbox control.

Comments

1

Add a textbox at desired location at desig time same code genrated in designer file. Copy the code and paste under Command1_Click().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.