有关更新GUI的问题 [英] Question regarding updating GUI

查看:65
本文介绍了有关更新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;
  }

推荐答案

使用  

 


这篇关于有关更新GUI的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆