日期:2014-05-20  浏览次数:20770 次

这样的动态加载控制Lable如何弄?
已存在   1--100个Lable
命名为Lable1   Lable2,Lable100规律
需要每个Lable显示规律数

Lable1.Text=200
Lable2.Text=199
Lable3.Text=198
Lable100.Text=101



------解决方案--------------------
for (int i = 1; i <= 200; i++)
{
Label lbl = (Label)this.Controls.Find( "Label " + i.ToString(), true)[0];
if (lbl != null)
{
lbl.Text = (201 - i).ToString();
}
}
------解决方案--------------------

int n = 0;
int m = 0;
int top = 6;
Button[] button_area = new Button[53];
DataSet ds = new DataSet();
ds = dbconn.selectArea(); //重数据库读去按照使用率排列的省名

this.textBox1.Text = " ";
this.Card = " ";

// 动态添加按钮并根据使用情况排列顺序按钮
for (int i = 0; i < 53; i++)
{
button_area[i] = new Button();
//button_area[i].BackColor = System.Drawing.Color.White;
if (i == 0 | i == 24 | i == 48)
{
button_area[i].Location = new System.Drawing.Point(top, 20);
m = 0;
n = 0;
}
else
{

if (i % 4 == 0)
{
n++;
m = 0;
button_area[i].Location = new System.Drawing.Point(top + m * 45, 20 + n * 42);
}
else
{
m++;
button_area[i].Location = new System.Drawing.Point(top + m * 45, 20 + n * 42);
}
}
button_area[i].Font = new System.Drawing.Font( "宋体 ", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
button_area[i].Size = new System.Drawing.Size(37, 36);
button_area[i].TabIndex = i + 5;
button_area[i].UseVisualStyleBackColor = true;
button_area[i].Text = ds.Tables[0].Rows[i][0].ToString();
button_area[i].Click += new EventHandler(button_area_Click);
this.Controls.Add(button_area[i]);
}

可以参考这个例子!