C#之线程、委托,强强联手操作窗体控件...
本例子程序完整源码下载地址:
http://download.csdn.net/download/friendan/4346742
写本程序的目的,是为了理解委托
...
http://download.csdn.net/download/friendan/4346742
写本程序的目的,是为了理解委托
![吐舌头](http://static.blog.csdn.net/xheditor/xheditor_emot/default/tongue.gif)
效果截图如下:
主要代码如下:
//线程处理函数 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; } }
探索代码的奥秘,享受技术的乐趣-_-!...