Pages

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:

  1. Anonymous3:54 PM

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

    THX for this hint

    ReplyDelete
  2. Anonymous8:04 PM

    Amazing,it works :D

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

    ReplyDelete