所以我有一个自定义的WF控件,里面有一些形状和文字。这些物体往往经常移动。因为没有像this.DoubleBuffered = true或“WS_EX_COMPOSITED”工作(至少对我来说)摆脱闪烁,我设法创建一个非常简单的双缓冲自己。问题是渲染非常慢。只有小分辨率才足够快。
它的工作原理如下:
Graphics g;
Bitmap buffer;
public SomeControl()
{
InitializeComponent();
buffer = new Bitmap(this.Width, this.Height);
g = Graphics.FromImage(buffer);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
g.Clear(BackColor);
//some painting with "g"
e.Graphics.DrawImageUnscaled(buffer, Point.Empty);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
buffer = new Bitmap(this.Width, this.Height);
g = Graphics.FromImage(buffer);
}
void Repaint()
{
this.InvokePaint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
}
protected override void OnMouseMove(MouseEventArgs e)
{
//Move something around
Repaint();
}
如果我不用“g”绘制它,而是用“e.Graphics”绘制它,它足够快(但它闪烁)。那么,使用WF控件进行双缓冲有更快的方法吗?谢谢!
(如果我的英语不好,也很抱歉)