如何更新从另一个类Windows窗体GUI? [英] how to update a windows form GUI from another class?

查看:131
本文介绍了如何更新从另一个类Windows窗体GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何更新从中创建图形用户界面,但不是在创建线程另一个阶级的胜利形式的控制(例如标签,进度条)? (例如,Program.cs中的事件处理程序)

how do you update a win forms control (ex. label, progress bar) from another class which created the GUI but not in the creating thread? (for example, an event handler of Program.cs)

我发现关于使用invoke()方法从另一个线程更新界面的几个职位,但我已经什么如果代码写在同一个班的形式迄今为止发现的唯一作品

I've found several posts regarding updating GUI from another thread using Invoke() method, but what i've found so far only works if the codes are written in the same class as the form

http://www.yoda.arachsys.com/csharp/threads/winforms.shtml

推荐答案

您需要调用调用形式方法。例如:

You need to call the Invoke method on the form. For example:

private void someMethod() {
    myOtherForm.Invoke(new MethodInvoker(delegate() {
        // update things in myOtherForm here
    }));
}

如果您不需要返回回前完成更新方法,你应该使用的BeginInvoke 而不是调用

If you don't need the updates to be finished before returning back to the method, you should use BeginInvoke instead of Invoke.

这篇关于如何更新从另一个类Windows窗体GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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