如何双缓冲面板? [英] How do I double buffer a Panel?

查看:29
本文介绍了如何双缓冲面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有轮盘的面板,我需要对面板进行双重缓冲,以使其停止闪烁.谁能帮帮我?

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?

是的,我试过了.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆