有关更新GUI的问题

问题描述:

对于C#编程我还是很陌生,而对于一般的编程来说,我还是有些陌生.我正在尝试在Visual C#中创建Windows窗体应用程序(使用C#Express),但我真正不明白的是如何更新GUI.假设我有 一个简单的表单(Form1),其中有一个标签NumLabel.我希望NumLabel从0到5000进行计数,并在每次数字增加时进行更新.我一直在研究委托,调用等,但是无法正常工作.这是我的 UpdateLabel委派代码:

I'm pretty new to C# programming and somewhat new to programming in general.  I'm trying to create a Windows Forms Application in Visual C# (using C# Express), but what I really don't understand is how to get the GUI to update.  Let's say I have a simple form (Form1), and in it is a single label NumLabel.  I want that NumLabel to count from 0 to 5000 and update every time it the number goes up.  I've been looking into delegate, invoke, etc, but I can't get things to work.  Here is my UpdateLabel delegation code:

 

void
 UpdateLabelText(Label lbl, string
 text)
  {
   UpdateLabelTextDelegate dlg = new
 UpdateLabelTextDelegate(UpdateLabelTextByDelegate);
   lbl.Invoke(dlg, new
 object
[] { lbl, text });
  }

  void
 UpdateLabelTextByDelegate(Label lbl, string
 text)
  {
   lbl.Text = text;
  }

使用