我一直在寻找这个问题,但我不能让它工作:( 这是我的代码:
using System.Drawing;
namespace Chess.Source
{
public sealed class GraphicsBuffer
{
private Graphics graphics;
private int height;
private Bitmap memoryBitmap;
private int width;
public Graphics Graphics
{
get { return graphics; }
}
public void CreateGraphicsBuffer(Graphics g, int W, int H)
{
if (memoryBitmap != null)
{
memoryBitmap.Dispose();
memoryBitmap = null;
}
if (graphics != null)
{
graphics.Dispose();
graphics = null;
}
if (W == 0 || H == 0)
return;
if ((W != width) || (H != height))
{
width = W;
height = H;
memoryBitmap = new Bitmap(width, height);
graphics = Graphics.FromImage(memoryBitmap);
}
}
public void Render(Graphics g)
{
if (memoryBitmap != null)
{
g.DrawImage(memoryBitmap, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel);
}
}
}
}
答案 0 :(得分:0)
闪烁很可能是因为您没有使用double buffering。
您可以通过将其DoubleBuffering
属性设置为true
来对您要绘制的表单元素启用双缓冲。
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered(v=vs.110).aspx