111,129
社区成员
发帖
与我相关
我的任务
分享List<string> list = new List<string>();
list.Add("壹");
list.Add("贰");
list.Add("叁");
int sp = 20;
for (int i = 0; i < list.Count; i++)
{
Label lab = new Label();
lab.Text = list[i];
lab.Name = "lab_" + i;
lab.Size=new Size(sp, sp);
lab.Location = new Point(sp * i, sp * i);
Controls.Add(lab);
} List<string> list = new List<string>();
list.Add("壹");
list.Add("贰");
list.Add("叁");
int locationIndex = 50;
Color color = Color.Red;
if (list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
string lblValue = (string)list[i];
Label lb = new Label();
lb.Name = "lbl" + i;
lb.Text = lblValue;
lb.BackColor = color;
lb.Size = new Size(20, 20);
lb.Location = new Point(locationIndex, locationIndex);
this.Controls.Add(lb);
locationIndex += 20;
color = Color.Blue;
}
}
int i = 0;
foreach (Control c in this.Controls)
{
if (c is Label)
{
c.Text = list[i];
i++;
}
}
foreach (Control c in this.Controls)
{
if (c is Label)
{
c.Text = "";//赋list中的值,将哪个值插到那个label中,自己改
}
}