views:

92

answers:

1

I am drawing an grid-work of objects in a Panel. when I scroll the the panel quickly I get a flicker. I thought that enabling the double buffering may take care of this but what I find is that it does not completely draw everything and I am left with blank sections. could anyone give me suggestions as to what may be happening and how I might correct it.

UPDATE:

I found that I was creating the graphics object with Creategraphics() rather than using the Parameter in the paint method

+1  A: 

How did you set the double buffering?

You should either set the DoubleBuffered property of the control to true

public UserControl1()
{
  InitializeComponent();
  this.DoubleBuffered = true;
}

Or

Use SetStyle, and set both OptimizedBoubleBuffer and AllPaintingInWmPaint

public UserControl1()
{
  InitializeComponent();
  SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);      
}

ControlStyles.AllPaintingInWmPaint instructs the control to ignore WM_ERASEBKGND messages. This will reduce the flicker you see especially from the scrolling. This is implied with when setting the DoubleBuffered property to true, in fact it makes the same call to SetStyle as in the second example.

Chris Taylor