Adding controls at runtime


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Adding controls at runtime

  1. #1
    Chris Lucas Guest

    Adding controls at runtime


    I am trying to create objects on a form at run time. I believe this is
    possible although as usual MSDN is not very forthcoming about this subject.
    Quite simply I would like to create and display additional textboxes at
    run time on a form. This is done in response to the end user's commands
    and so creating a lot of invisible controls at design time is not a valid
    solution. Any help anyone can offer would be most appreciated. Thanks.

    Chris

  2. #2
    Colin McGuigan Guest

    Re: Adding controls at runtime


    "Chris Lucas" <cdl1051@earthlink.net> wrote in message
    news:3b49c92c$1@news.devx.com...
    >
    > I am trying to create objects on a form at run time. I believe this

    is
    > possible although as usual MSDN is not very forthcoming about this

    subject.
    > Quite simply I would like to create and display additional textboxes at
    > run time on a form. This is done in response to the end user's commands
    > and so creating a lot of invisible controls at design time is not a valid
    > solution. Any help anyone can offer would be most appreciated. Thanks.


    Assuming VB6:

    Make a module level Long variable, which we'll call m_lngControl. The point
    of this variable is to allow us to generate non-repeating names.

    Private m_lngControl As Long

    Private Sub cmdAdd_Click()
    Dim ctlAny As Control

    m_lngControl = m_lngControl + 1
    Set ctlAny = Controls.Add("VB.Textbox", "txt" & m_lngControl)
    ctlAny.Visible = True
    End Sub



  3. #3
    Chris Lucas Guest

    Re: Adding controls at runtime


    Worked like a champ, thanks very much Colin.

    "Colin McGuigan" <cmcguigan@imany.com> wrote:
    >
    >"Chris Lucas" <cdl1051@earthlink.net> wrote in message
    >news:3b49c92c$1@news.devx.com...
    >>
    >> I am trying to create objects on a form at run time. I believe this

    >is
    >> possible although as usual MSDN is not very forthcoming about this

    >subject.
    >> Quite simply I would like to create and display additional textboxes

    at
    >> run time on a form. This is done in response to the end user's commands
    >> and so creating a lot of invisible controls at design time is not a valid
    >> solution. Any help anyone can offer would be most appreciated. Thanks.

    >
    >Assuming VB6:
    >
    >Make a module level Long variable, which we'll call m_lngControl. The point
    >of this variable is to allow us to generate non-repeating names.
    >
    >Private m_lngControl As Long
    >
    >Private Sub cmdAdd_Click()
    > Dim ctlAny As Control
    >
    > m_lngControl = m_lngControl + 1
    > Set ctlAny = Controls.Add("VB.Textbox", "txt" & m_lngControl)
    > ctlAny.Visible = True
    >End Sub
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center