I was in the exact same predicament as you. I put a Panel inside of a C# WinForm and used it as a display zone for a geometric animation. Multiple redraw operations triggered by a timer, combined with the occasional window resizing, all caused that Panel to flicker terribly. The other solutions offered here all seem to rely on activating the DoubleBuffered
flag, but this never made any difference in my experience.
The proper way to go about it is to use the System.Drawing.BufferedGraphics
class and harness it in your application.
Here's an overview of it, and an example that actually works (no more flickering!).
That example is a bit overkill since it highlights at least two ways to perform the rendering before flipping the graphic buffers; you only need to keep the one you prefer in your implementation.
I personally chose to subclass the Panel into a new DoubleBufferedPanel
class. I simply use the base Panel's Paint()
method combined with a call to Refresh()
to flip the buffers.