This is my code. When I move cursor over Form it works, circle is moving but it is blinking. How can I fix this?
public partial class Preprocesor : Form
{
in
How bout overriding a panel user control and set Doublebuffered
to true?
public partial class BufferPanel : Panel
{
public BufferPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
}
}
You need to draw on a double-buffered control.
Make a class that inherits Control
and sets DoubleBuffered = true; in the constructor (this is a protected property).
Use that control instead of your panel it there won't be any flickering.
Also, you should not store a Graphics
object for later.
Instead, you should draw on e.Graphics
in the Paint
handler.