面板双缓冲
通过将“AllPaintingInWmPaint”、“UserPaint”和“DoubleBuffer”ControlStyles 的值设置为“true”,可以对整个表单进行双缓冲(this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,真)
)。
但这对于 System.Windows.Forms.Panel 来说是不可能发生的,因为该类不允许我这样做。我找到了一种解决方案:http://bytes. com/topic/c-sharp/answers/267635-double-buffering-panel-control。我也尝试过这个: Winforms 双缓冲 。它很滞后,即使它在一张小绘图上使用,我也有一些在表单和其他内容中使用的自定义资源,因此我不会将整个表单变成一张绘图。第二个似乎会引起问题。还有其他方法可以做到这一点吗?
我问这个问题是因为我不希望在调整表单大小时面板上的绘图一直闪烁。如果有一种方法可以在不使用双缓冲的情况下消除闪烁,我将很高兴知道。
Double buffering the whole form can be done by setting the value of the "AllPaintingInWmPaint", "UserPaint" and "DoubleBuffer" ControlStyles to "true" (this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true)
).
But this can't happen with a System.Windows.Forms.Panel because the class doesn't allow me to do so. I have found one solution: http://bytes.com/topic/c-sharp/answers/267635-double-buffering-panel-control . I have also tried this: Winforms Double Buffering . It's laggy, even when it's used on a small drawing, I have some custom resources that I'm using in the form and other things because of which I won't turn the whole form into one drawing. And the second one seems to cause problems. Are there other ways to do that?
I'm asking this because I don't want the drawing on the panel to flash all the time when the form is being resized. If there is a way to get rid of the flashing without double buffering, I'll be happy to know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果不需要滚动支持,请使用 PictureBox,默认情况下它是双缓冲的。获得双缓冲可滚动面板非常容易:
ResizeRedraw 分配抑制了容器控件的绘制优化。如果您在面板中进行任何绘画,您将需要它。如果没有它,当您调整面板大小时,绘画会出现污点。
双缓冲实际上会使绘画速度变慢。这会对稍后绘制的控件产生影响。它们在被填充之前留下的洞可能会暂时可见,也被视为闪烁。您可以在此中找到针对该影响的对策回答。
Use a PictureBox if you don't need scrolling support, it is double-buffered by default. Getting a double-buffered scrollable panel is easy enough:
The ResizeRedraw assignment suppresses a painting optimization for container controls. You'll need this if you do any painting in the panel. Without it, the painting smears when you resize the panel.
Double-buffering actually makes painting slower. Which can have an effect on controls that are drawn later. The hole they leave before being filled may be visible for a while, also perceived as flicker. You'll find counter-measures against the effect in this answer.
我应该很久以前就发布我的解决方案......
好吧,这是我的解决方案:
让我觉得自己像个十足的白痴,在问这个问题多年后找到了这个解决方案。
我已经用面板尝试过此操作,但事实证明在应用新图像时速度会更慢。我在某处读到,最好使用面板而不是图片框。不过,我不知道是否必须在代码中添加一些内容来加快面板的速度。
I should have posted my solution a long time ago...
Well, here is my solution:
Makes me feel like a complete idiot for finding this solution years after asking this question.
I have tried this with a Panel, but it has proven to be slower when applying the new image. Somewhere I had read, that it is better to use Panel instead of PictureBox. I don't know if I have to add something to the code to speed things up for the Panel, though.
如果可以的话,您可以在调整大小时停止刷新面板,然后再次启用它,这样您就可以摆脱难看的闪烁。
If acceptable you can stop refreshing the panel while resizing and enable it again after, this way you get rid of the ugly flickering.