0

Hello,

I need a label array for my windows form so I can easily edit the text in the labels.
I've found this solution:

for (int i = 0; i < 10; i++)
            {
                Label[] labels = new Label[10];
                labels[i] = new Label();
                labels[i].Text = "0";
                labels[i].Location = new System.Drawing.Point(100, i*10+100);
            }

I put this code in the form load.
It's not giving me errors but It's not displaying the labels on the screen either.

Can anyone help me?

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by lt johnson
0

I didn't any other code except the code shown here so should there be code that tells the form it has new labels?

1

You forgot to add the control to the forum,you add controls with the instruction this.Controls.Add(control here).
This is the corect code :

Label[] labels = new Label[10];
for (int i = 0; i < 10; i++)
{
     labels[i] = new Label();
     labels[i].Text = "0";
     labels[i].Location = new System.Drawing.Point(100, i * 10 + 100);
     this.Controls.Add(labels[i]);
}
0

Add the control to your form using the method
"this.controls.add(yourcontrol_obj_name)"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.