如何对面板进行双缓冲?
我有一个带有轮盘赌轮的面板,我需要对面板进行双缓冲,以使其停止闪烁。 谁能帮我吗?
编辑:
是的,我已经尝试过了。
panel1.doublebuffered不存在,只有this.doublebuffered。 我不需要缓冲表单,只需缓冲面板。
I have a panel that has a roulette wheel on it, and I need to double buffer the panel, so that it stops flickering. Can anyone help me out?
EDIT:
Yes, I have tried that.
panel1.doublebuffered does not exist, only this.doublebuffered. And I don't need to buffer the Form, just the Panel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
另一种方法是使用 InvokeMember 方法调用成员 doublebuffered:
通过这种方式,您不必创建子类
Another way of doing this is to invoke the member doublebuffered, using the InvokeMember method:
By doing it this way, you don't have to create a subclass
您需要从Panel 或PictureBox 派生。
这会产生一些影响,具体取决于您选择启用缓冲的方式。
如果你设置了 this.DoubleBuffer 标志那么你应该没问题。
如果您手动更新样式,那么您必须自己在 WM_PAINT 中绘制表单。
如果您确实雄心勃勃,您可以维护并绘制自己的后台缓冲区作为位图。
You need to derive from Panel or PictureBox.
There are ramifications to this depending on how you choose to enable the buffering.
If you set the this.DoubleBuffer flag then you should be ok.
If you manually update the styles then you have to paint the form yourself in WM_PAINT.
If you really feel ambitious you can maintain and draw your own back buffer as a Bitmap.
您可以在
Panel
的派生类中将DoubleBuffered
-Property 设为公共:You can make the
DoubleBuffered
-Property public in a derivided class ofPanel
:Winform 面板具有 DoubleBuffered 属性 。
编辑:我应该注意到它受到保护。 其他人已经描述了如何对其进行子类化。 :)
Winform panels have a DoubleBuffered property.
Edit: I should have noticed that it was protected. Others have described how to sub-class it. :)
只是扩展 User79775 的答案,如果你想在 VB.net 中实现这一点,请这样做:
Just expanding on User79775's answer, if you're trying to achieve this in VB.net, do so like this:
我和你遇到了完全相同的困境。 我将一个面板放入 C# WinForm 中,并将其用作几何动画的显示区域。 由计时器触发的多次重绘操作,加上偶尔调整窗口大小,都会导致面板严重闪烁。 这里提供的其他解决方案似乎都依赖于激活 DoubleBuffered 标志,但这对我的经验没有任何影响。
正确的方法是使用 System.Drawing.BufferedGraphics 类并在应用程序中利用它。
这是概述< /a> ,以及一个 示例实际上有效(不再闪烁!)。
这个例子有点矫枉过正,因为它强调了在翻转图形缓冲区之前至少有两种执行渲染的方法; 您只需要在实施中保留您喜欢的那个即可。
我个人选择将 Panel 子类化为新的
DoubleBufferedPanel
类。 我只是使用基本面板的Paint()
方法并结合调用Refresh()
来翻转缓冲区。I was in the exact same predicament as you. I put a Panel inside of a C# WinForm and used it as a display zone for a geometric animation. Multiple redraw operations triggered by a timer, combined with the occasional window resizing, all caused that Panel to flicker terribly. The other solutions offered here all seem to rely on activating the
DoubleBuffered
flag, but this never made any difference in my experience.The proper way to go about it is to use the
System.Drawing.BufferedGraphics
class and harness it in your application.Here's an overview of it, and an example that actually works (no more flickering!).
That example is a bit overkill since it highlights at least two ways to perform the rendering before flipping the graphic buffers; you only need to keep the one you prefer in your implementation.
I personally chose to subclass the Panel into a new
DoubleBufferedPanel
class. I simply use the base Panel'sPaint()
method combined with a call toRefresh()
to flip the buffers.