c# WINFORM Label.Text动态赋值问题!

ivanho 2010-09-19 03:37:20
情况是这样:

从数据库里产生了一个IList (表示可按照索引单独访问的对象的非泛型集合.),这个IList包含着多个要赋给Label.Text的值。

但由于Lable是动态生成的,所以不太懂。。。


如:IList里有:"壹""贰""参"

对应:Label1.Text=“壹”,Lable2.Text=“贰”,Lable3.Text=“参”

望高手们赐教。。。
...全文
1094 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
混乱之序 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 qq123592624 的回复:]

C# code
List<string> list = new List<string>();
list.Add("壹");
list.Add("贰");
list.Add("叁");
int locationIndex = 50;
Color color = Color.……
[/Quote]
好久没写wf程序了 知道要找坐标忘记怎么定义了 哈
谢谢 提醒
顺便贴下 代码
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);
}
beg200710 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 qq123592624 的回复:]
C# code
List<string> list = new List<string>();
list.Add("壹");
list.Add("贰");
list.Add("叁");
int locationIndex = 50;
Color color = Co……
[/Quote]
学习
编程爱好者L 2010-09-19
  • 打赏
  • 举报
回复
 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;
}
}
huwen7565833 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 linwanhai 的回复:]
C# code

int i = 0;
foreach (Control c in this.Controls)
{
if (c is Label)
{
c.Text = list[i];
i……
[/Quote]
Up!!!!!
linwanhai 2010-09-19
  • 打赏
  • 举报
回复

int i = 0;
foreach (Control c in this.Controls)
{
if (c is Label)
{
c.Text = list[i];
i++;
}
}
ivanho 2010-09-19
  • 打赏
  • 举报
回复
还是没搞懂。。。
linwanhai 2010-09-19
  • 打赏
  • 举报
回复

foreach (Control c in this.Controls)
{
if (c is Label)
{
c.Text = "";//赋list中的值,将哪个值插到那个label中,自己改
}
}
华仔lugl 2010-09-19
  • 打赏
  • 举报
回复 1
每天回复可得分
q107770540 2010-09-19
  • 打赏
  • 举报
回复
for (int i = 0; i < 10; i++)
{
Label l = this.Controls("Label" + i) as Label;
l.Text = "";
}

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧