在C#中,我定义的标签很多(Label+k )
来源:百度知道 编辑:UC知道 时间:2024/05/23 00:23:08
如同for (int i= i ;<=12;i++)
{
label+k.txt=i.tostring;
}
可是总是不行
for (int i = i; i <= 12; i++)
{
foreach (Control aa in this.Controls)
{
if (aa.GetType() == typeof(Label))
{
Label lab = (Label)aa;
if (lab.Name = "Label" + i.ToString())
{
lab.Text = i.ToString();
}
}
}
}
如果是web!
把this.Controls改为外部容器就好咯!只要不是Page
我在我的电脑上调试过了可以,VS2008 Windows From程序
foreach (Control cont in this.Controls)
{
if (cont.GetType() == typeof(Label))
{
Label lb = (Label)cont;
string str = lb.Name.ToString();
lb.Text = str[5].ToString();
}