
-----------------------------------
GlobeTrotter
Wed Nov 23, 2005 6:37 pm

Adding Controls At Run-Time
-----------------------------------
I want to be able to click a button that will in turn add more instances of a frame on each click.  On my form, I have one frame already, index number 0.  This is the code for the cmd_click procedure.


    Load fraTextNum(fraTextNum.Count)
    fraTextNum(fraTextNum.Count - 1) = fraTextNum(0)
    With fraTextNum(fraTextNum.Count - 1)
        .Top = fraTextNum(fraTextNum.Count - 1).Top + fraTextNum(fraTextNum.Count - 1).Height + 30
        .Caption = "Text File #" & CStr(fraTextNum.Count)
        .Visible = True
    End With


It seems to work if I press it once, and it creates another one underneath it.  However, when I try and press it again, it does not create a third instance.  Any ideas why?  I'm stumped.

-----------------------------------
Brightguy
Wed Nov 23, 2005 9:47 pm

Re: Adding Controls At Run-Time
-----------------------------------
Actually you're just creating them all in the same spot.

You're setting the new frame's Top to be fraTextNum(fraTextNum.Count - 1).Top + fraTextNum(fraTextNum.Count - 1).Height + 30, but fraTextNum(fraTextNum.Count - 1).Top was just set to the first frame's Top.

You probably want to add on the Top of the previous frame created instead, that is, fraTextNum(fraTextNum.Count - 2).Top

-----------------------------------
GlobeTrotter
Wed Nov 23, 2005 11:21 pm


-----------------------------------
Thanks, that was stupid.

Now, what if I want to do the exact same thing for, say, a textbox but have the new instance of the textbox inside the frame I just created?

When I try and do it, the textbox I create is stuck inside the original frame.  I can't really see any properties I can change at run-time to select the frame it should be in, could you help please?

-----------------------------------
Brightguy
Fri Nov 25, 2005 3:54 pm

Re: Adding Controls At Run-Time
-----------------------------------
Set Option1.Container = Frame1
