Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Creation of new controls

Status
Not open for further replies.

MrMoocow

Programmer
May 19, 2001
380
US
Is it possible to create controls while the program is running

ie

user clicks new window,
the program adds a WHOLE new tab with a WHOLE new textbox ( or internet control ect ect).

is it possible?

Thank you very much your all very helpful.



Brad
 
You have to create a control array. Once you've done that, you can load more controls at runtime. For example, to add two textboxes:
Load textbox1(1)
Load textbox1(2)

To get rid of them:
Unload textbox1(2)
Unload textbox1(1)
 
Wiat so I just use the code load object(number) ?
 
Yep, if you have one textbox named txtMyText(0) and you want to create another one just like it, say Load txtMyText(1). This may not appear to work at first, because Visual Basic correctly assumes that you're going to want to move the new control before it's visible to the user. Once you've positioned the new control in its new location, be sure to call a txtMyText.Visible = True, and there it is.
 
Yeah, but you have to have a control array first (that is you have to have a control on your form at design time with a 0 subscript e.g. textbox1(0))
 
Can these have indepentant texts and properties from each other ie
text(0).text = 1
text(1).text = 2

Thanks

I'm actually working with the internet control at the moment though
 
Yep, they certainly can have independant properties; they are all different, seperate instances.
 
iN case anyone is wondering I'm making a tabbed browser, with a button to dynamicaly add either a browser, html editor, or javascript editor, tabs.
 
The only problem you might run into is with properties you can't change at runtime. For example, I used this technique with listboxes, but I couldn't set the multiselect property at runtime for the dynamic controls I loaded. I had to have two seperate listbox control arrays, one that was single select and one that was multiselect.
 
'This coding will work for dynamically adding textboxes, labels, etc.

Private WithEvents lblObject As Label

Private Sub Form_Load()
Set lblObject = Me.Controls.Add ("VB.label", "lblTime") 'Create label dynamically
lblObject.Visible = True
lblObject.Caption = "Dynamic Label"
End Sub

'------------------------------------------------------

The only question I have which I have not yet been able to find any documentation, or anything on is how to add an ARRAY of objects dynamically.
EX:
lblTime(0)
lblTime(1)
lblTime(2)

Does anyone know how to do this?

Aaron
 
I encountered this post when i was looking for the same answer. :D

If you're still looking: thread222-14902 might be helpfull

regards,
johpje
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top