通过另一个线程修改一个控件(winforms) [英] Modify a control (winforms) through another thread

查看:31
本文介绍了通过另一个线程修改一个控件(winforms)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

Public Class main

    Public Shared classOne As classOne 
    Public Shared classTwo As classTwo

    Public Shared Sub main()

        classOne = new classOne()
        classTwo = new classTwo()

        classTwo.myThread.Start()

        Application.Run(classOne)
    End Sub

End Class

classOne 是一个带有文本标签的简单 winform.我只是想从 classTwo 修改这个 textlabel 的背景颜色,但是有一个问题,因为 classTwo 在另一个线程中.

classOne is a simple winforms with a textlabel. I just would like modify the background color of this textlabel from classTwo but there is a problem because classTwo is in an other thread.

我知道我必须使用委托和调用方法,但我不知道该怎么做.我应该在哪里声明委托函数以及我必须在哪里使用 invoke 方法?我已经使用了 MSDN 文档,但我未能应用它...

I know I must use a delegate and invoke method but i don't know how to do it. Where should I declare the delegate function and where I have to use invoke method please? I have already ridden the MSDN documentation but I failed to apply it...

推荐答案

请阅读以下文章:

MSDN - 如何:制作线程-安全调用 Windows 窗体控件

MSDN - 如何:使用背景搜索文件的线程

MSDN - Control.Invoke 方法(委托, Object())

MSDN - Control.InvokeRequired 属性

我想这对人们来说太过分了.:\

i guess this is too much for people. :\

这篇关于通过另一个线程修改一个控件(winforms)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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