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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add controls in vb.net programmatically 1

Status
Not open for further replies.

PC888

Programmer
Nov 7, 2003
117
CA
Could someone give me a hint how this could be done?
I have added 10 labels (using an array), and I have assigned true to .visible and .enable properties, but I do not see them on the form.
I know in VB6, one would put the .index value to non-zero, but in vb.net, I cannot find the .index property.
Thanks a million.
 
You don't have arrays as such in .NET like you could in VB6

To simply add a label at runtime you need something similar to this

Dim lbl as New Label

lbl.name = "lbl1"
lbl.text = "Something"
lbl.Left = 5

and so on setting your properties.

Then you need to add it to your page...lets say a panel on your form.

Panel1.Controls.Add(lbl)

You can create an array and then use the above code to generate each label.
 
Everything works perfectly now, thanks for your info, sjn78.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top