怎样用委托把list中的值赋值到label上去

totodele 2010-12-27 04:38:44
List<string> list = new List<string>();
string strTemp = this.sp.ReadTo("\r\n").Replace("\0", "");

int count = 0;
int num = 0;
foreach (Control ctl in this.label1.Parent.Controls)
{
count++;
if (list.Count == 0)
{
if (ctl.Text == "0000000000")
{
list.Add(strTemp);
}
}
}
...全文
179 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-12-28
  • 打赏
  • 举报
回复
invoke操作
public delegate void Test(int index);
public partial class Form1 : Form {
private Test TestProgress;
public Form1() {
InitializeComponent();
this.TestProgress= new Test(Te);
}
private void Te(int index) {
if (this.InvokeRequired) {
this.Invoke(this.TestProgress, new object[] { index });
}
else {
this.label1.Text = index.ToString();
}
}
private void button1_Click(object sender, EventArgs e) {
Thread thread = new Thread(new ThreadStart(ThreadMethod));
thread.Start();
}
private void ThreadMethod() {
int i = 0;
while (true) {
Thread.Sleep(1000);
i++;
this.TestProgress(i);
}
}
}
totodele 2010-12-28
  • 打赏
  • 举报
回复
if (list.Count == 0)
我前面写的这个判断是当扫描枪每次扫描时候都重新创建了一次list 所以这样写的
但是,用委托去把list中的值复制到 当前的label中我不会用委托求助
totodele 2010-12-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wxr0323 的回复:]
引用 1 楼 totodele 的回复:

对委托一知半解 脑子很混 坐等高手 求解...

没看懂你的代码 你想实现什么功能?
一个Lable 赋 多个值?
还是多个Lable 多个值?
[/Quote]多个label 通过扫描枪扫描一个赋一个 label中的 初值赋的是“000000” 扫描后的值把原本的值替换掉

List<string> list = new List<string>();
string strTemp = this.sp.ReadTo("\r\n").Replace("\0", "");//扫描得到的值

int count = 0;
int num = 0;
foreach (Control ctl in this.label1.Parent.Controls)//遍历label
{
count++;

if (ctl.Text == "0000000000")//判断当label中值为“000000”进入
{
如何让它扫描一个修改一个label呢,怎样去做判断呢
list.Add(strTemp);//添加进list
利用委托给label赋值
}

}
子夜__ 2010-12-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 totodele 的回复:]

对委托一知半解 脑子很混 坐等高手 求解...
[/Quote]
多贴点儿代码上来
子夜__ 2010-12-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 totodele 的回复:]

对委托一知半解 脑子很混 坐等高手 求解...
[/Quote]
没看懂你的代码 你想实现什么功能?
一个Lable 赋 多个值?
还是多个Lable 多个值?
totodele 2010-12-27
  • 打赏
  • 举报
回复
对委托一知半解 脑子很混 坐等高手 求解...

17,747

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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