我需要在界面上动态加载N多的控件,想在线程中创建控件,并添加到主界面上,怎么解决!急! 如题所示,请大神帮我解决!.net 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用委托 ,google “c# 线程 委托” 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); } } 那你在创建循环里加上DoEvents,就不会卡了 //线程动态创建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); Application.DoEvents(); //加上这句 } } 大神,确实可以了,我去看看MSDN的这个Application.DoEvents()是什么意思! 水晶报表 交叉报表 列重复显示 string 转 float 的问题 c# 中英文版问题 如何用.net GDI+来画这样的箭头呢?(带附件地址) 选择menu中的delete时,如何清除对应控件选中内容 socket编程,多端口 100分:谁详细讲一下静态方法在何处使用?静态方法在何处使用?有什么好处? 这是怎么回事? 初学者问题,请高手指教,解决后立即结贴 WPF里面的日期控件可以有选择框吗?? chart 控件 框选图表。 sql update语句,急!
{
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);
}
}
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);
Application.DoEvents(); //加上这句
}
}