Results 1 to 5 of 5

Thread: creating runtime controls

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    16

    creating runtime controls

    I am trying to create a form that allows the user to enter the number of text box controls they want to generate and then have the form generate these controls triggered via the click event of the submit button.

    It appears I could do this as 2 forms and create the 2nd form dynamically but I thought I could use the same form and simply add the new controls to the Controls() collection and then refresh the form rather than closing the old form and opening a new one.

    Does anyone have any thoughts or ideas?

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    There should be no problems adding the controls to the existing form.
    Show us the code you use, maybe we can point out some mistakes.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    16

    found my own answers again

    Well, once again I posted something and somehow imemdiately answered my own question. As it turns out, this is quite easy. I just set some controls within the onclick even of a button and I did not need to call a refresh.

    Dim myLabel As Label = New Label()
    Dim myLabel2 As Label = New Label()

    Me.Controls.Add(myLabel)
    Me.Controls.Add(myLabel2)

    myLabel.Text = "Dynamically added label control."
    myLabel.Left = 100
    myLabel.Top = 10

    myLabel2.Text = "Dynamically added label control."
    myLabel2.Left = 100
    myLabel2.Top = 35

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    This may be better:


    Dim myLabel As New Label
    Dim myLabel2 As New Label

    Me.Controls.Add(myLabel)
    Me.Controls.Add(myLabel2)

    myLabel.Text = "Dynamically added label control."
    myLabel.Left = 100
    myLabel.Top = 10

    myLabel2.Text = "Dynamically added label control."
    myLabel2.Left = 100
    myLabel2.Top = 35


    Wasn't much to it. You were nearly there.

    Have fun!


    «°°phReAk°°»

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    that works aswell. heh, sorry, i didnt see your second one.

    Apologies


    «°°phReAk°°»

    Visual Studio 6, Visual Studio.NET 2005, MASM

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