专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > WinForm

C# WinForm解决Panel控件中的图片刷新时会闪烁的有关问题

发布时间:2011-06-23 13:53:56 文章来源:www.iduyao.cn 采编人员:星星草
C# WinForm解决Panel控件中的图片刷新时会闪烁的问题

     最近在项目开发过程中,使用Panel控件显示座位背景图,在分屏切换时,发现背景图会闪烁。在同事的帮助下,通过以下方法解决了:

新建一个类,继承Panel控件类,然后开启该控件的双重辅助缓冲区,禁止擦除背景,具体请看代码:

1、新建一个NewPanel类,继续Panel控件类

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XC.Contorl
{
    /// <summary>
    /// 用途:防止Panel闪烁
    /// </summary>
    public partial class NewPanel : Panel
    {
        public NewPanel()
        {
            InitializeComponent();

            this.DoubleBuffered = true;//设置本窗体
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
        }

        public NewPanel(IContainer container)
        {
            container.Add(this);

            InitializeComponent();

            this.DoubleBuffered = true;//设置本窗体
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
        }
    }
}

 

2、引用新的Panel控件类

   在InitializeComponent() 中,添加以下代码:

   this.Panel1 = new XC.Contorl.NewPanel(this.components);

  通过以上发法即可解决图片闪烁问题,有错误或不足之处,望批评指正!

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: