1

I want to paint a plot diagram in a panel with 600 points per each 100 milliseconds. When I do it using Graphics object and simply draw an ellipse, the screen flashes! How can I draw such a diagram efficiently and without flashing?!

moorara
  • 3,897
  • 10
  • 47
  • 60
  • possible duplicate of [Double Buffering when not drawing in OnPaint(): why doesn't it work?](http://stackoverflow.com/questions/3113190/double-buffering-when-not-drawing-in-onpaint-why-doesnt-it-work) – Hans Passant Jul 21 '12 at 12:31

2 Answers2

0

An easy way to stop this is to turn double buffering on. Your form has a double buffered property which you can set to true.

Or sometimes you can do it on the control if it supports it.

e.g.

class MyForm : Form
{
    public MyForm()
    {
        InitializeComponent();
        this.DoubleBuffered = true;
    }
}
IntelOrca
  • 108
  • 2
  • 8
0

The panel's double buffering needs to be turned on via inheritance:

public class BufferedPanel : Panel {
  public BufferedPanel() {
    this.DoubleBuffered = true;
    this.ResizeRedraw = true;
  }
}

Then make sure you use the actual paint event of the control:

public Form1() {
  InitializeComponent();
  bufferedPanel1.Paint += bufferedPanel1_Paint;
}

private void bufferedPanel1_Paint(object sender, PaintEventArgs e) {
  e.Graphics.DrawSomething(...);
}

Avoid using CreateGraphics() as that is only a temporary drawing.

LarsTech
  • 80,625
  • 14
  • 153
  • 225