日期:2014-05-18  浏览次数:20945 次

控件重绘太慢
忽然觉得当窗体中的控件需要重绘的时候,控件都是一个一个刷出来的,效果很不好,即使只有一个控件要重绘,也能很明显的感觉出重绘前的空白,不知道有没有办法可以解决这个问题。

------解决方案--------------------
探讨
DoubleBuffer一点用都没有。


C# code
//这样就可以做到在内存中的某个图片里绘制。然后再把结果绘到某个控件,而这控件就只得到了一次绘制。这样效率就高了起来。

//创建虚拟绘制Bitmap,
Bitmap TampBmp = new Bitmap(this.Width, this.Height);
//创建虚拟绘制区域
Graphics TampG = Graphics.FromImage(TampBmp);

//绘制背景//然后绘制NNN
TampG.DrawImage(FormStyle_Images.FrameBottom, 0, 0, this.Width …

------解决方案--------------------
他肯定是说DoubleBuffered的属性没用。。。呵呵
其实你自己画到位图又能实现到什么程度呢?,别以为光把this给画进去了就行了,要屏蔽this的所有Child的Paint,然后将所有的Child的Paint画到你的位图上,同样,Child可能还有Child。。。
人家的DoubleBuffered是从Control类就有的,应该已经考虑这些问题了,估计设置的问题吧,去MSDN搜索一下OptimizedDoubleBuffer
这儿有双缓冲的例子
C# code
// This example assumes the existence of a form called Form1.
BufferedGraphicsContext currentContext;
BufferedGraphics myBuffer;
// Gets a reference to the current BufferedGraphicsContext
currentContext = BufferedGraphicsManager.Current;
// Creates a BufferedGraphics instance associated with Form1, and with 
// dimensions the same size as the drawing surface of Form1.
myBuffer = currentContext.Allocate(Form1.CreateGraphics(), 
   Form1.DisplayRectangle);