日期:2014-05-17 浏览次数:20885 次
public delegate void AddControlHanddler();
private void Form1_Load(object sender, EventArgs e)
{
new System.Threading.Thread(new System.Threading.ThreadStart(AddControlThread)).Start();
}
private void AddControlThread()
{
AddControlHanddler add = new AddControlHanddler(AddControlFunc);
this.Invoke(add);
}
//线程动态创建100个按钮
private void AddControlFunc()
{
for (int i = 0; i < 100; i++)
{
Button b = new Button();
b.Text="按钮" + (i+1).ToString();
b.Location = new Point(10, 10 + 30 * i);
b.Size = new Size(75, 24);
this.Controls.Add(b);
}
}