处理方式:布局挂起
panelContent.SuspendLayout();
panelContent.ResumeLayout();
private void button1_Click(object sender, EventArgs e) { panelContent.SuspendLayout(); this.panelContent.Controls.Clear(); string aa = DateTime.Now.ToString(); int k = 1; for (int j = 0; j < 200; j++) { Add(new QueueButton(), k, this.panelContent, 16, "18.00", "19.00", "Pm"); k++; } panelContent.ResumeLayout(); string bb = DateTime.Now.ToString(); MessageBox.Show(aa+" "+bb); }
启用窗体双缓存
CheckForIllegalCrossThreadCalls = false;
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
重写CreateParams方法
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;////用双缓冲绘制窗口的所有子控件
return cp;
}
}