【发布时间】:2009-02-22 13:58:06
【问题描述】:
我有一个 CF 2.0 应用程序,表单上有一个 PictureBox。我想通过鼠标移动来移动PictureBox,我需要在表单中添加Double Buffer以避免闪烁。
我该怎么做?
谢谢!
【问题讨论】:
标签: c# winforms compact-framework doublebuffered
我有一个 CF 2.0 应用程序,表单上有一个 PictureBox。我想通过鼠标移动来移动PictureBox,我需要在表单中添加Double Buffer以避免闪烁。
我该怎么做?
谢谢!
【问题讨论】:
标签: c# winforms compact-framework doublebuffered
你不需要双缓冲的表单,你需要的是 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 中没有的东西...
【讨论】: