NicoVB Posted December 24, 2003 Posted December 24, 2003 You have 1 label... how do you Add 4 copies of these to a panel??? If you do this: Dim i As Int16 , lbl As Label For i = 1 To 5 lbl = New Label lbl = Label1 Panel1.Controls.Add(lbl) Next The control collection contains 1 item how do I solve this??? Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Experts* mutant Posted December 24, 2003 *Experts* Posted December 24, 2003 (edited) If you don't set their location they all will end up in the default location therefore overlapping. [edit]Ah, sorry. Misread your post.[/edit] Edited December 24, 2003 by mutant Quote
NicoVB Posted December 24, 2003 Author Posted December 24, 2003 Nope, that's not the reason: here is the new code which still gives ONE collection item Dim i As Int16, lbl As Label, x As Int16, y As Int16 For i = 1 To 5 lbl = New Label lbl = Label1 lbl.Location = New Point(x, y) Panel1.Controls.Add(lbl) x += 1 y += 1 Next Console.Write(Panel1.Controls.Count) Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Experts* mutant Posted December 24, 2003 *Experts* Posted December 24, 2003 Trying to copy it like that won't work because all your label are essentially set to one label instance, they all will have the same handle, etc. so what you are doing is creating label objects that refer to one instance of the label therefore each time you try to add a label you actually modify the only label instance you have. And it doesn't matter if you added it before, same instance of the same control will not be added twice to the panel, therefore you only see one label. Quote
NicoVB Posted December 25, 2003 Author Posted December 25, 2003 No way to solve this?? Quote Visit http://www.nico.gotdns.com Now ONLINE!
Administrators PlausiblyDamp Posted December 26, 2003 Administrators Posted December 26, 2003 As mutant said don't set them to the same instance. Dim i As Int16, lbl As Label, x As Int16, y As Int16 For i = 1 To 5 lbl = New Label lbl.Location = New Point(x, y) Panel1.Controls.Add(lbl) x += 10 y += 10 lbl.Text= i Next Console.Write(Panel1.Controls.Count) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.