譬如设置控件的文本,
private void SetControlText2(Control c, string text) { if (c.InvokeRequired) { this.Invoke(new MethodInvoker(delegate() { SetControlText2(c, text); }), c, text); } else { c.Text = text; ; } }
上面这是简易的写法,要写成下面这种也可以;
private delegate void SetControlTextCallBack(Control c, string text); private void SetControlText(Control c,string text) { if (c.InvokeRequired) { this.Invoke(new SetControlTextCallBack(SetControlText), c,text); } else { c.Text = text; ; // btnTest.Text =bool( o); } }
时间: 2024-12-31 14:29:41