CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2000
    Posts
    4

    How to create textbox at run time

    I Need to create TextBox at run time ,kindly guide me how can I do that.I need user to input how many names he want to enter if he inputs 10 and OK 10 textbox i need to display if 50 than 50 so kindly guide me.Thanking u in anticipation ,
    Vipul


  2. #2
    Join Date
    Jan 2000
    Posts
    45

    Re: How to create textbox at run time

    just put those 50 textboxes already on the form, but set their visiblility to false, and then when you want those 50 to show set the visibility to true.


  3. #3
    Join Date
    Aug 1999
    Location
    Pakistan
    Posts
    366

    Re: How to create textbox at run time

    Use the following.This code adds menus at runtime .U can try to add text boxes.If not then tell me I willsne u code that

    option Explicit

    Dim gClick as Integer 'Variable to moniotor Clicks
    private Sub mnuOpen_Click()
    on error GoTo MyError

    CommonDialog1.CancelError = true 'Catch the Cancel Button
    gClick = gClick + 1 'set gClick to 1

    'Show the CommonDialog Open BOx
    CommonDialog1.ShowOpen

    'Load the first Menu
    Load mnuLatestFile(gClick + 1)

    'set the visible property to true
    mnuLatestFile(gClick + 1).Visible = true

    'Change the caption to the file that the user selected
    mnuLatestFile(gClick + 1).Caption = CommonDialog1.FileName
    Exit Sub

    MyError:
    Exit Sub
    End Sub





  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: How to create textbox at run time

    Here's one way that works with VB 4, 5 and 6 :


    Create a form (FORM1) with a textbox (Text1) and a command button (Command1). Set the 'Index' property of Text1 to '0' and paste in the following code :


    option Explicit
    '
    private Sub Command1_Click()
    Dim l as Long
    Dim sVal as string
    '
    sVal = InputBox("How many textboxes ?")
    '
    If sVal = "" then Exit Sub
    '
    l = CLng(sVal)
    '
    CreateTextBoxes l
    '
    End Sub
    '
    private Sub CreateTextBoxes(byval l as Long)
    '
    Dim lCount as Long
    '
    for lCount = 1 to l
    '
    Load Text1(lCount)
    With Text1(lCount)
    .Top = Text1(lCount - 1).Top + Text1(lCount - 1).Height + 25
    .Width = Text1(lCount - 1).Width
    .Left = Text1(lCount - 1).Left
    .Visible = true
    End With
    next
    '
    End Sub




    The program will create the specified number of textboxes underneath the existing one (change the positioning in the CreateTextBoxes routine). When you want to handle events for each textbox, you'll need to remember to check the 'Index' property for each one (if relevant).



    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  5. #5
    Guest

    Re: How to create textbox at run time

    Why waste system resources loading 50 textboxes, when you can create them at run-time. Using a control array, put a textbox on the form with the index 0, then in your code when you need a new one just use Load textbox_name(new_index). Just make sure you control the index_number or you will end up with bogus boxes.


  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: a bit of knowledge for a smart trick

    ;-)
    '
    '


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured