Can't Seem To Dynamically Generate Labels

S

Steven C

Hello:

I'm trying to dynamically generate some labels for a form, and I can't
seem to get it to work. The code is as follows. The first label is
generated, but subsequent labels are not. Is there a better technique
for this

for(int i=0; i <= intLabCount; i++)
{
strArrLabAccounts = "lblCaption" + Convert.ToString(i).Trim();
Label lblNewLabel = new Label();
lblNewLabel.Parent = this.pgLiveView;
lblNewLabel.Text = "Yahoo" + Convert.ToString(i);
lblNewLabel.Location = new System.Drawing.Point(i*50,20);
lblNewLabel.Visible = true;
lblNewLabel.Name = strArrLabAccounts.ToString();
}
 
C

Cor Ligthert [MVP]

Steven,

I think you overdo it, but at least I miss something as

Controls.Add(lblNewLabel);

Cor
 
S

Stoitcho Goutsev \(100\)

Steven,

I don't see anywhere in to code to add the labels to the form (or some other
control).

Could it be the the problem or you kust missed that line of code in the
snippet that you posted.
I find it strangle that you say the first label is only created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top