天天看点

C# 线程中打开新窗体

方法一:

MethodInvoker MethInvk = new MethodInvoker(ShowForm5);
BeginInvoke(MethInvk);  
           
private void ShowForm5()
{
    Form5 form5 = new Form5();
    form5.Show();
}
           

这种 委托方法不能带参数

方法二:带参数的委托方法

ShowFormHandler delShowForm = new ShowFormHandler(ShowForm5);
this.BeginInvoke(delShowForm, new Object[] { stripaddr, type });
           
public delegate void ShowFormHandler(string stripaddr, int type );
 private void ShowForm5(string stripaddr, int type )
 {
     Form5 form5 = new Form5( stripaddr, type );
     form5.Show();
 }