CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2000
    Location
    Belgium
    Posts
    27

    Creating new objects at runtime

    Hi,

    How can I create new instances of a control on runtime ?

    my main-control is named picture1
    I tried something like this

    dim p as object
    set p = new picture1
    .....

    But this doesn't work.
    Does anybody knows how I can make this work ?
    Thanx



  2. #2
    Join Date
    Jan 2000
    Location
    CA
    Posts
    52

    Re: Creating new objects at runtime

    The easiest way to do this is to ensure that your Picture1 control is assigned an Index Number (e.g. 0) when it is created. Then you can add or remove instances of the Picture1 by using

    Load Picture1(Picture1.count)

    The number of Picture1 objects is 1 when the program is started. The starting index is 0, so when this Load statement is encountered, the program will create Picture1(1). You can Unload controls that were created dynamically. You cannot Unload controls that were in existence at design time.

    Good Luck...


  3. #3
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Creating new objects at runtime

    when you place a control on the form set it's index property to 0. then use something like this:

    'assuming a textbox named txtControls
    dim x as integer
    x = ubound(txtControls) + 1
    Load txtControls(x)
    txtcontrols(x).visible = true
    txtControls(x).Text = "I created this at runtime"



    Hope this helps,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

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