C#界面控件过多导致界面闪烁卡顿
1.在窗体中加入下面的代码
#region 开启界面双缓冲 解决窗体切换闪屏问题
//下面的代码许加在MDI窗体中
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
#endregion
2.自定义双缓冲panel
public partial class MyPanel : Panel
{
protected override void OnPaintBackground(PaintEventArgs e)
{
//do not allow the background to be painted
}
/**#region 开启界面双缓冲 解决窗体切换闪屏问题
//下面的代码许加在MDI窗体中
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
#endregion
protected override void WndProc(ref Message m) {
if (m.Msg == 0x0014) // 禁掉清除背景消息
return;
base.WndProc(ref m);
} **/
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
// 使用双缓冲
this.DoubleBuffered = true;
// 背景重绘移动到此
if (this.BackgroundImage != null)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
e.Graphics.DrawImage(
this.BackgroundImage,
new System.Drawing.Rectangle(0, 0, this.Width, this.Height),
0,
0, this.BackgroundImage.Width, this.BackgroundImage.Height, System.Drawing.GraphicsUnit.Pixel);
}
base.OnPaint(e);
}
}
还没有评论,来说两句吧...