如何对面板进行双重缓冲? [英] How do I double buffer a Panel?
问题描述
我有一个带有轮盘的面板,我需要对该面板加倍缓冲,以使其停止闪烁.有人可以帮我吗?
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?
是的,我已经尝试过了.
Yes, I have tried that.
panel1.doublebuffered不存在,只有this.doublebuffered.而且我不需要缓冲表单,只需缓冲面板.
panel1.doublebuffered does not exist, only this.doublebuffered. And I don't need to buffer the Form, just the Panel.
推荐答案
您需要从Panel或PictureBox派生.
You need to derive from Panel or PictureBox.
这取决于您选择启用缓冲的方式.
There are ramifications to this depending on how you choose to enable the buffering.
如果设置this.DoubleBuffer标志,则应该没问题.
If you set the this.DoubleBuffer flag then you should be ok.
如果您手动更新样式,则必须在WM_PAINT中自己绘制表单.
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.
using System.Windows.Forms;
public class MyDisplay : Panel
{
public MyDisplay()
{
this.DoubleBuffered = true;
// or
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
}
}
这篇关于如何对面板进行双重缓冲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!