且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#CF,WinForms和双缓冲区

更新时间:2022-06-26 06:09:52

您不需要Form双重缓冲,需要PB.在CF中很难做到这一点.但是,您可以创建自己的控件,PB非常简单.例如:

You don't need the Form double-buffered, you need the PB to be. That's not so easy to come by in CF. However, you could create your own control, PB is pretty simple. For example:

using System;
using System.Drawing;
using System.Windows.Forms;

public class MyPictureBox : Control {
  private Image mImage;
  public Image Image {
    get { return mImage; }
    set { mImage = value; Invalidate(); }
  }
  protected override void OnPaintBackground(PaintEventArgs pevent) {
    // Do nothing
  }
  protected override void OnPaint(PaintEventArgs e) {
    using (Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height)) {
      using (Graphics bgr = Graphics.FromImage(bmp)) {
        bgr.Clear(this.BackColor);
        if (mImage != null) bgr.DrawImage(mImage, 0, 0);
      }
      e.Graphics.DrawImage(bmp, 0, 0);
    }
    base.OnPaint(e);
  }
}

希望我没有使用CF中没有的东西...

Hopefully, I didn't use stuff that isn't available in CF...