【发布时间】:2016-05-24 08:06:47
【问题描述】:
我想设置你正在使用的线程在另一个线程上创建的控件。
在不同线程上创建的控件:PictureBox PBox、SplitContainer _sc
enter code here
class Class1
{
public Class1(SplitContainer _sc,PictureBox PBox)
{
SetPanel(_sc,PBox);
}
delegate void SetPanelDele(SplitContainer _sc, PictureBox pb);
void SetPanel(SplitContainer _sc, PictureBox pb)
{
if (pb.InvokeRequired && _sc.InvokeRequired)
{
pb.Invoke(new SetPanelDele(SetPanel), new object[] { _sc, pb });
}
else
{
pb.Parent = _sc.Panel2; // here
}
}
}
【问题讨论】:
-
那么问题是什么?
-
你应该检查
this.InvokeRequired,而不是pb.InvokeRequired
标签: c# multithreading