Adding Controls At Run-Time
Author |
Message |
GlobeTrotter
|
Posted: Wed Nov 23, 2005 6:37 pm Post subject: 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.
code: |
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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Wed Nov 23, 2005 9:47 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
GlobeTrotter
|
Posted: Wed Nov 23, 2005 11:21 pm Post subject: (No subject) |
|
|
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? |
|
|
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Fri Nov 25, 2005 3:54 pm Post subject: Re: Adding Controls At Run-Time |
|
|
VisualBASIC: | Set Option1.Container = Frame1 |
|
|
|
|
|
![](images/spacer.gif) |
|
|