在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级
private void menuItemFoo_Click(object sender, System.EventArgs e)
{
System.Threading.Thread thread=new System.Threading.Thread(new System.Threading.ThreadStart(this.Foo));
thread.Start();
}
public delegate void MyDelegate(Form form);
System.Windows.Forms.Form childForm;
private void AddMdiChild(Form form)
{
form.MdiParent=this;
form.Show();
}
private void Foo()
{
childForm=new Form();
//childForm.MdiParent=this; //直接调用会出错
//childForm.Show();
this.Invoke(new MyDelegate(this.AddMdiChild),new object[]{childForm});
}
{
System.Threading.Thread thread=new System.Threading.Thread(new System.Threading.ThreadStart(this.Foo));
thread.Start();
}
public delegate void MyDelegate(Form form);
System.Windows.Forms.Form childForm;
private void AddMdiChild(Form form)
{
form.MdiParent=this;
form.Show();
}
private void Foo()
{
childForm=new Form();
//childForm.MdiParent=this; //直接调用会出错
//childForm.Show();
this.Invoke(new MyDelegate(this.AddMdiChild),new object[]{childForm});
}