i got a problem with flickering in C# WinForms proyect.
I simply made a SlideButton control: this is the code:
using System;
using System.Collections.Gen
One day I ran into this problem as well. The simplest (maybe not the most elegant) solution was to remove the OnPaintBackground()
and add it into the normal OnPaint()
method because otherwise the background is painted onto your last Gfx each time the control is invalidated what causes the flickering:
public ctor()
{
// this does just work with OptimizedDoubleBuffer set to true
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// do NOT paint the background here but in OnPaint() to prevent flickering!
//base.OnPaintBackground(e);
}
protected override void OnPaint(PaintEventArgs e)
{
// do the background and the base stuff first (if required)
base.OnPaintBackground(e);
base.OnPaint(e);
// ... custom paint code goes here ...
}
You might give it a try, good luck.