Monday, April 21, 2008

Avoid flickering in C# custom control


Whent it is set BackgroundImage to custom control and Invalidate is call you can see flickering. To avoid that try like this:

publicpartial class MyControl: UserControl
{
public MyControl()
{
SetStyle(ControlStyles.AllPaintingInWmPaint ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}

3 comments:

Anonymous said...

Great!! That's what I was looking for...

THX for this hint

Anonymous said...

Amazing,it works :D

Martin Larsson said...

Works like a charm!
I added ControlStyles.UserPaint though, because it said so...