Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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???

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Experts*
Posted (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 by mutant
Posted

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)

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Experts*
Posted
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.
  • Administrators
Posted

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)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...