1.在窗体中设置

this.DoubleBuffered = true;//设置本窗体

            SetStyle(ControlStyles.UserPaint, true);

            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.

            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲

2.在控件中设置

 SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲

3.自定义Panel绘制Bitmap背景

 public class BackgroundPanel : Panel
      {
          protected override void OnPaintBackground(PaintEventArgs e)
          {
              return;
          }

         protected override void OnPaint(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);
         }
     }

发表评论

邮箱地址不会被公开。 必填项已用*标注