Friday, 13 September 2013

How do I dynamically create a list of controls or labels that have the same properties of a pre-existing one VB.net

How do I dynamically create a list of controls or labels that have the
same properties of a pre-existing one VB.net

When I try to create a list of labels with the same properties as a
pre-existing one using the code below, while I end up with a list 10 items
long, they all end up having the same name and there ends up only being
one label displayed.
I suspect that I am ending up with a list of 10 "pointers" to the same
label. (But I'm using the word "New" every chance i get :) )
Dim lblList As New List(Of Label)
For I = 0 To 9
lblList.Add(New Label)
lblList(I) = lblExistingLabelWithDesiredProperties
lblList(I).Name = "lblName" & I.ToString
lblList(I).Left = 30 + I * 10
Next
As I say I seem to end up with only one label.
Thanks in advance.

No comments:

Post a Comment