我正在使用C#/ .Net中的简单矢量绘图应用程序.绘图是在一个面板中完成的,但是我并没有对所有这些事件使用OnPaint()事件 - 实际上OnPaint()甚至只调用另一个实际绘制文档中所有内容的方法.
我尝试添加双缓冲,但是当我将DoubleBuffered设置为true时,闪烁问题更加严重.为什么是这样?如果我想双重缓冲控件,我是否必须使用提供的Graphics对象在OnPaint()事件中完成所有绘图,而不是使用Panel.CreateGraphics()然后绘制到那个?
编辑:这是我正在使用的基本代码.
private void doc_Paint(object sender, PaintEventArgs e)
{
g = doc.CreateGraphics();
Render(ScaleFactor, Offset);
}
private void Render(float ScaleFactor, PointF offset)
{
foreach (Line X in Document.Lines) { DrawLine(X.PointA, X.PointB, X.Color, X.LineWidth); }
}
private void DrawLine(PointF A, PointF B, Color Color, float Width)
{
Pen p = new Pen(Color, Width);
PointF PA = new PointF(((A.X + Offset.X) * ScaleFactor), ((A.Y + Offset.Y) * ScaleFactor));
PointF PB = new PointF(((B.X + Offset.X) * ScaleFactor), ((B.Y + …Run Code Online (Sandbox Code Playgroud)