时间:2019-03-07 标签:c#CF、WinForms和双缓冲区

发布于 2024-07-14 18:17:14 字数 122 浏览 5 评论 0原文

我有一个 CF 2.0 应用程序,表单上有一个 PictureBox。 我想用鼠标移动来移动 PictureBox,并且需要向表单添加双缓冲区以避免闪烁。

我怎样才能做到这一点?

谢谢!

I have a CF 2.0 app with a PictureBox on a Form. I want to move the PictureBox with mouse move and I need to add Double Buffer to the form to avoid flickering.

How can I do this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2024-07-21 18:17:14

您不需要 Form 双缓冲,您需要 PB 双缓冲。 这在CF里可不是那么容易做到的。 但是,您可以创建自己的控件,PB 非常简单。 例如:

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 中没有的东西......

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);
  }
}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文