首页 WinForm/WPF Winform实时更新Label变化的动态值

Winform实时更新Label变化的动态值

作者:胡同里的砖头 围观群众:2850 更新于:2013-12-19

 public partial class Form1 : Form
    {
       
public delegate void ShowLable(string count,Label lab);

       
public Form1()
        {
            InitializeComponent();
        }

       
private void button1_Click(object sender, EventArgs e)
        {
            Thread thread
= new Thread(new ThreadStart(Test));
            thread.Start();
        }

       
public void Test()
        {
           
for (int i = 0; i < 100; i++)
            {
                ShowLables(i.ToString(), label1);
                System.Threading.Thread.Sleep(
100);
            }
        }
       
public void ShowLables(string  count,Label lab)
        {
           
if (lab.InvokeRequired)
            {
                ShowLable ss
= new ShowLable(ShowLables);
               
this.Invoke(ss, new object[] { count, lab });
            }
           
else
            {
                lab.Text
= count.ToString();
            }
        }
    }

  • 本文标题: Winform实时更新Label变化的动态值
  • 文章分类:【WinForm/WPF】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8