C#之线程、委托,强强联手操作窗体控件...

本例子程序完整源码下载地址:
http://download.csdn.net/download/friendan/4346742


写本程序的目的,是为了理解委托吐舌头...

效果截图如下:



主要代码如下:

//线程处理函数
        public void threadProc()
        {
            setTextBox("测试成功");
        }

        //声明委托
        delegate void myDelegate(String text);

        //实现委托方法
        public void setTextBox(String text)
        {
             //判断是否要调用文本框对象的invoke方法
             if(this.textBox.InvokeRequired)
             {
                 //创建委托对象
                 myDelegate degSetText = new myDelegate(setTextBox);

                 //调用文本框对象的invoke方法
                 this.textBox.Invoke(degSetText, new object[] { text });
             } 
             else
             {
                 this.textBox.Text = text;
             }
        }



posted @ 2012-06-02 13:44  氺〤魚Oo。  阅读(249)  评论(0编辑  收藏  举报