在Windows窗体中处理时更新标签 [英] Update Label while processing in Windows Forms
本文介绍了在Windows窗体中处理时更新标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在处理时在Windows Forms应用程序上更新标签的最佳方法是什么?
What is the best way to update a label on a Windows Forms application while processing?
我有一个循环,当用户单击按钮时,该循环会对用户系统上的文件进行一些处理.
I have a loop that does some processing to files on the user's system when the user clicks a button.
foreach (System.IO.FileInfo f in dir.GetFiles("*.txt"))
{
// Do processing
// Show progress bar
// Update Label on Form, "f.Name is done processing, now processing..."
}
一些示例代码是什么?
这到底叫什么?是线程还是委托?
What exactly is this called? Is it threading or delegates?
推荐答案
一个快速解决方案是:
Label1.Text = f.Name + " is done processing, now processing...";
Label1.Refresh();
您真的想避免使用DoEvents
,否则,如果用户反复按表单上的按钮,则会遇到问题.
You really want to avoid DoEvents
, otherwise you'll have problems if your user repeatedly presses buttons on your form.
这篇关于在Windows窗体中处理时更新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文