How can I draw on Panel so it does not blink?

拥有回忆 提交于 2019-12-01 21:15:14

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.

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();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!