日期:2014-05-17 浏览次数:20937 次
//首先声明一个委托
delegate void ShowMethod(object o);
ShowMethod s;
public Form1()
{
s=new ShowMethod(OperateCom);
//声明新的线程并调用方法
Thread newThread = new Thread(ThreadOperate);
newThread.Start();
}
private void ThreadOperate()
{
this.Invoke(s, new object[] { "操作" });
}
private void OperateCom(object o)
{
Button btn1 = new Button();
btn1.Text = o.ToString();
btn1.Name = "btnOperate";
btn1.Click+=new EventHandler(btn1_Click);
this.Controls.Add(btn1);
}
private void btn1_Click(object sender, EventArgs e)
{
MessageBox.Show("谢谢");
}