次のペイント関数を考えてみましょう (省略形):
public void paint(object sender, PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
BufferedGraphicsContext context = BufferedGraphicsManager.Current;
BufferedGraphics buffer = context.Allocate(g, e.ClipRectangle);
buffer.Graphics.Clear(Color.PaleVioletRed);
// skip drawing if cond is true (condition is not relevant)
if(!cond)
{
try
{
// l is some List<p>
foreach(Point p in l)
{
// ...calculate X and Y... (not relevant)
buffer.Graphics.FillEllipse(new SolidBrush(Color.Blue), p.X,p.Y, Point.SIZE,Point.SIZE);
}
}
catch {} // some exception handling (not relevant)
finally{
buffer.Render(g);
}
}
buffer.Render(g);
}
上記のコードは多かれ少なかれ疑似コードであることに注意してください。BufferedGraphics オブジェクトを使用して、ちらつきがなくなることを願っていました。実際、そうではありませんでした。最初は、paint-method には時間がかかりすぎると思っていましたが、おそらくそうではありませんでした (呼び出しごとに 4 ~ 7 ミリ秒を測定しました)。trueに設定cond
すると、ペイント メソッドにはほとんど時間がかかりませんが、まだちらつきます。paint-method がパネルにペイントし、タイマーを使用して約 50 ミリ秒ごとにパネルを無効にすることが重要な場合があります。最終的にちらつきをなくすにはどうすればよいですか?