1

次のペイント関数を考えてみましょう (省略形):

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 ミリ秒ごとにパネルを無効にすることが重要な場合があります。最終的にちらつきをなくすにはどうすればよいですか?

4

1 に答える 1

2

コンストラクターでプロパティを設定してみてください。

this.DoubleBuffered = true;

次に、BufferedGraphics のものは必要ありません。

public void paint(object sender, PaintEventArgs e)
{
  base.OnPaint(e);

  Graphics g = e.Graphics;       
  g.Clear(Color.PaleVioletRed);

  // skip drawing if cond is true (condition is not relevant)
  if(!cond)
  {
    // l is some List<p>
    foreach(Point p in l)
    { 
      // ...calculate X and Y... (not relevant)  
      g.FillEllipse(new SolidBrush(Color.Blue), p.X,p.Y, Point.SIZE,Point.SIZE);
    }                                          
  }
}
于 2013-03-03T13:34:23.867 に答える