如何更新从另一个类Windows窗体GUI?

编程入门 行业动态 更新时间:2024-10-27 12:28:50
本文介绍了如何更新从另一个类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

的 www.yoda.arachsys/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?

本文发布于:2023-11-11 06:40:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577658.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   Windows   GUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!