实时刷新winform中的某一个控件上的文字


 

需要注意的是,必须从UI线程,另外启动一个线程才可以。

在新线程调用异步刷新就OK了

 Thread thread;

        private void button1_Click(object sender, EventArgs e) { thread = new Thread(new ThreadStart(AnotherRefresh)); thread.IsBackground = true; thread.Start(); } private void AnotherRefresh() { MyRefresh("hello world"); Thread.Sleep(1000); MyRefresh("Bye Bye"); } private void MyRefresh(string str) { try { this.Invoke((MethodInvoker)delegate() { textBox1.Text = str; }); } catch (Exception ex) { MessageBox.Show(ex.Message); } }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM