public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync();
} private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Button bb = new Button();
bb.Location = new System.Drawing.Point(90, 90);
bb.Name = "button12";
bb.Size = new System.Drawing.Size(75, 23);
bb.TabIndex = 0;
bb.Text = "button1";
bb.UseVisualStyleBackColor = true;
this.Controls.Add(bb);
this.ResumeLayout(false);
}
}backgroundWorker1 是 backgroundWorker
为什么 主船体中显示不出来 button12 按钮呢
{
public Form1()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync();
} private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Button bb = new Button();
bb.Location = new System.Drawing.Point(90, 90);
bb.Name = "button12";
bb.Size = new System.Drawing.Size(75, 23);
bb.TabIndex = 0;
bb.Text = "button1";
bb.UseVisualStyleBackColor = true;
this.Controls.Add(bb);
this.ResumeLayout(false);
}
}backgroundWorker1 是 backgroundWorker
为什么 主船体中显示不出来 button12 按钮呢
private delegate void addcontrolmethod(Control ctl);
private void addcontrol(Control ctl)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new addcontrolmethod(this.addcontrol), new object[] { ctl });
}
else
{
this.Controls.Add(ctl);
}
}
把原来的this.Controls.Add(bb);
改为this.addcontrol(bb);