Flickering when resizing controls...

G

Guest

I have a form with a number of panel controls on it. I have overriden the
paint event (of the panel controls) to provide custom painting. What I have
done is to use the Paint event to paint the background colour of a number of
panel controls to be a gradient colour. This works fine. Is there a better
way??

The problem I have is that when I resize the parent form I get alot of
flickering as the paint events are constantly fired. I have used Double
Buffering where possible but this does not appear to resolve the problem.

Any suggestions for reducing flickering when resizing controls with
overriden Paint events?

Many thanks.
 
C

ClayB

If your call is to paint the background of the panel, then you might
consider overridng OnPaintBackground instead of OnPaint. There is also
a style property you can use in the contructor to affect whether
things are redrawn when the control is sized. (But normally, you need
the redrawing to happen to dynamically see your sizing.)

public class MyPanel : Panel
{
public MyPanel()
{
SetStyle(ControlStyles.ResizeRedraw, true);
}

protected override void OnPaintBackground(PaintEventArgs e)
{
// base.OnPaintBackground(e);
using (Brush b = new
System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new
Point(this.ClientSize.Width, this.ClientSize.Height),
Color.Red, Color.Blue))
{
e.Graphics.FillRectangle(b, this.ClientRectangle);
}

}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
==============
Clay Burch
Syncfusion, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top