Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create controls dynamically with a loop in windows forms.

What I have tried:

I have tried to write code to make that with a list of controls, but it hasn't been working yet
groupBox show only one label after the loop

C#
List<Label> labels = new List<Label>();
           for (int i = 0; i < 8; i++)
           {
               labels.Add(new Label());
               labels[i].Location = new Point(6 + i, 26 + i);
               labels[i].Text = "test";
               labels[i].Size = new Size(70, 40);
               groupBox3.Controls.Add(labels[i]);
           }
Posted
Updated 16-Jun-19 4:16am
v2

"i" is too small for varying Point; the labels are offset by only 1 pixel with (26 + i).

I think you intended something like (i * 26) for y.
 
Share this answer
 
Comments
Maciej Los 16-Jun-19 10:07am    
5ed!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900