C#不閃爍FORM繪圖方法
C#不閃爍FORM繪圖方法
資料來源: http://blog.csdn.net/wuyazhe/article/details/7691393
1.在建構函數中,執行
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
2.在Paint事件回應函數中,執行
BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
Graphics g = myBuffer.Graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
g.Clear(this.BackColor);
//使用g進行繪圖
myBuffer.Render(e.Graphics);
g.Dispose();
myBuffer.Dispose();//釋放資源