您的位置:首页 > 其它

解决 在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级

2014-02-27 13:54 936 查看
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(CreateUI));
t.Start();
}

private void CreateUI()
{
AddTextBox();
}

private void AddTextBox()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate { AddTextBox(); }));
return;
}
TextBox tb = new TextBox();
tb.Text = "test";
this.Controls.Add(tb);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐