问题描述
我们在DataGridViews中出现了一个性能问题,其中redraw是非常慢的,找到了解决方案创建一个派生类型,并在控件上启用双缓冲。
(由于DoubleBuffered属性被保护,所以需要派生类型)
We had a performance issue with DataGridViews where the redraw was horridly slow and found the solution Here to create a derived type and enable double buffering on the control.(Derived type is necessary since the DoubleBuffered property is protected)
将DoubleBuffered属性设置为true似乎没有任何缺陷。 / p>
It doesn't seem like there's any drawback to having the DoubleBuffered property set to true.
推荐答案
它受到保护,因为DGV继承了Control的属性。而Control.DoubleBuffered是受保护的。这是有道理的,因为每个衍生的控制应该决定自己转向。控制用户任意打开或关闭它是没有意义的。 DGV设计师决定关闭。
It is protected because DGV inherits the property from Control. And Control.DoubleBuffered is protected. Which makes sense because each derived control should decide for itself to turn that on. And it doesn't make sense for the control user to arbitrarily turn it on or off. The DGV designers decided for off.
他们可能已经决定这是双缓冲实际上使绘画变慢的一个原因。渲染缓冲区位图的额外步骤花费时间。它只是看起来更快的人眼,你观察到位图突然出现。您无法看到绘制到位图所需的时间。除非其他控件需要绘制,并且在DGV之后轮到它们,那么它是相当明显的。
One reason they might have decided that is that double buffering actually makes painting slower. The extra step to render the buffer bitmap costs time. It just looks faster to the human eye, you observe the bitmap suddenly appearing. You can't see the time it takes to draw into the bitmap. Unless other controls need to be painted and they get their turn after the DGV, then it is quite visible.
你看到的是首先绘制的形式,控制器去。那些洞有一个白色的背景。当您使用TransparencyKey或Opacity属性时,黑色。每个控件然后获取Paint事件,并且一个接一个地填充孔。这种效果被用户感觉为闪烁,尽管它是与DoubleBuffered解决的闪烁不同的闪烁。当背景是黑色时,这是特别值得注意的。
What you see is the form getting drawn first, with holes where the controls go. Those holes have a white background. Black when you use the TransparencyKey or Opacity property. Each control then gets the Paint event and the holes are filled one-by-one. That effect is perceived as flicker too by the user, although it is a different kind of flicker from the one that DoubleBuffered solves. It is especially noticeable when the background is black.
需要解决这个问题的是整个表单与其所有的控件是双缓冲的。这在Windows窗体中不可用。但是,Windows XP和更高版本实际上支持这一点。检查看看这是怎么回事。请注意,它可以具有该线程中记录的副作用。
What's needed to solve this problem is that the entire form, with all its controls, is double-buffered. That's not available in Windows Forms. However, Windows XP and later actually support this. Check this thread to see how that's done. Beware that it can have side-effects as documented in that thread.
这篇关于为什么DataGridView中的DoubleBuffered属性默认为false,为什么会受到保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!