110,528
社区成员
发帖
与我相关
我的任务
分享
FORM1.Invoke(new MethodInvoke(myMethod));
//FORM:
private void Form1_Load(object sender, EventArgs e)
{
Class1 c1 = new Class1();
Thread xc = new Thread(c1.xiancheng);
xc.Start(this);//启动线程的时候,要在这里将FORM传递过去
}
//CLASS1:
namespace WindowsApplication1
{
delegate void MethodInvoke(Form1 frm1);//申明委托,带一个FORM1参数
class Class1
{
public void xiancheng(object frm)
{
Form1 frm1 = (Form1)frm;//在这里要将OBJECT转为FORM1
frm1.Invoke(new MethodInvoke(weituo),frm1 );//调用委托,并且传递FRM1
}
public void weituo(Form1 frm1)
{
frm1.Text = "123";//修改FORM1窗体的标题
}
}
}