最近在项目开发过程中,使用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.Dou