Create Text Boxes at Run Time in VB.6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ANURAG JAIN
    New Member
    • Oct 2007
    • 4

    Create Text Boxes at Run Time in VB.6

    Hi,

    Can any help to create textboxes in VB.06 on run time.

    please provide the code if anybody have.

    Thanks in advance
    Anuarg Jain
    Last edited by Killer42; Dec 20 '07, 11:34 PM.
  • DarthCrap
    New Member
    • Dec 2007
    • 3

    #2
    Code For VB6
    Code:
    Private Sub Form_Load()
        Dim controlname As String
        For i = 1 To 6  '   Change
            controlname = "txtControl" & CStr((i))
            Call Controls.Add("VB.TextBox", controlname, Me)
            With Controls(controlname)
                .Left = 56 ' Change
                .Top = (i - 1) * 480 ' Change
                .Visible = True
            End With
        Next i
    End Sub
    That should work - just modify as needed

    Edit : Hold On - VB.06 - Do you mean VB 6.0?

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Of course, the simpler technique is to create a textbox at design time, set the Index property to 0 to make it a control array, then just use the Load statement to add new ones at run time. This makes them more convenient to work with, too.

      Comment

      • vdraceil
        New Member
        • Jul 2007
        • 236

        #4
        Killer's advice is the best to create run time controls.
        If you want the code, look below.

        Create a textbox named text1(0) to begin a control array

        [CODE=vb]Dim i As Integer

        Private Sub Command1_Click( )
        Load text1(i+1)
        ' You may align the new control with its top & left properties
        text1(i + 1).Top = text1(i).Top + text1(i).Width + 15
        text1(i + 1).Left = text1(i).Left
        i = i + 1
        End Sub[/CODE]

        All the best
        Last edited by Killer42; Dec 24 '07, 09:26 PM.

        Comment

        Working...