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?

Where is the code that tells the form it has new labels?

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

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]);
}

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

Thanks! that fixed the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.