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);
        }
 
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值