标签名称中的变量? [英] Variable in a label name?

查看:83
本文介绍了标签名称中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我想做以下事情:


我的表单上有10个标签,名为Label0到Label9。现在我想一次改变所有标签的Text属性,例如:


for(int i = 0; i< 10; i ++ )

{

Label(i).Text ="你好,这是标签:" + i.ToString();

}


现在,当然,这不会奏效。但是怎么做呢?


感谢您的帮助,

Tinus

解决方案

如何在表单上放置标签?我会以不同的方式处理这个问题

,具体取决于您是通过设计师还是通过代码创建它们。


" Tinus" < no **************** @ xxx.karssemeijer.com.noadv.xxx>在消息中写道

新闻:ee *************** @ TK2MSFTNGP10.phx.gbl ...

你好,

我想做以下事情:

我的表单上有10个标签,名为Label0到Label9。现在我想立即更改所有标签的Text属性,例如:

for(int i = 0; i< 10; i ++)
{
标签(i).Text ="你好,这是标签:" + i.ToString();
}
现在,当然,这不会奏效。但是怎么做呢?

感谢您的帮助,
Tinus



如何添加标签到在InitializeComponent之后你的ctor中的一个数组然后你可以写出几乎完全相同的代码


问候


Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
< a rel =nofollowhref =http://www.dotnetconsult.co.uktarget =_ blank> http://www.dotnetconsult.co.uk


你好,


我想做以下事情:


我的表单上有10个标签,名为Label0到Label9。现在我想一次改变所有标签的Text属性,例如:


for(int i = 0; i< 10; i ++ )

{

Label(i).Text ="你好,这是标签:" + i.ToString();

}


现在,当然,这不会奏效。但是怎么做呢?


感谢您的帮助,

Tinus


< blockquote> Tinus,


你的意思是这个

\\

foreach(控制ctr in this.Controls)

{

if(ctr is Label)

if(ctr.Name.Substring(0,5)==" label")

ctr.Name = ctr.Name.Substring(5);

}

///


我希望这有帮助吗?


Cor


Hello,

I want to do the following:

I have 10 labels on my form, called Label0 to Label9. Now I want to change
the Text property of all the labels at once, e.g.:

for (int i = 0; i < 10; i++)
{
Label(i).Text = "Hello, this is label: "+i.ToString();
}

Now, ofcourse this won''t work. But how can this be done?

Thanks for your help,
Tinus

解决方案

How do you put the labels on your form? I would handle this differently
depending on whether you were creating them through the designer or in code.

"Tinus" <no****************@xxx.karssemeijer.com.noadv.xxx > wrote in message
news:ee***************@TK2MSFTNGP10.phx.gbl...

Hello,

I want to do the following:

I have 10 labels on my form, called Label0 to Label9. Now I want to change
the Text property of all the labels at once, e.g.:

for (int i = 0; i < 10; i++)
{
Label(i).Text = "Hello, this is label: "+i.ToString();
}

Now, ofcourse this won''t work. But how can this be done?

Thanks for your help,
Tinus



How about adding your Labels to an array in your ctor after InitializeComponent then you can write almost exactly that code

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hello,

I want to do the following:

I have 10 labels on my form, called Label0 to Label9. Now I want to change
the Text property of all the labels at once, e.g.:

for (int i = 0; i < 10; i++)
{
Label(i).Text = "Hello, this is label: "+i.ToString();
}

Now, ofcourse this won''t work. But how can this be done?

Thanks for your help,
Tinus


Tinus,

You mean something as this
\\
foreach ( Control ctr in this.Controls)
{
if (ctr is Label)
if (ctr.Name.Substring(0,5) == "label")
ctr.Name = ctr.Name.Substring(5);
}
///

I hope this helps?

Cor


这篇关于标签名称中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆