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);

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

时间: 2024-08-07 20:53:21

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

[C#]实现panel控件的双缓冲刷新

默认的panel控件在重画时会出现闪烁的问题 解决问题的方法是在继承原有panel属性的基础上赋予它双缓冲的功能 在Form类中添加如下代码 1 /// <summary> 2 /// 双缓冲panel 3 /// </summary> 4 public class DoubleBufferPanel : Panel 5 { 6 public DoubleBufferPanel() 7 { 8 this.SetStyle(ControlStyles.AllPaintingInWmP

解决嵌入WinForm的WPF控件无法显示图片问题

解决办法是在控件初始化时,通过下面方法再次加载图片: ucCanvas.CreateCoordinateImage.Source = GetImageIcon(global::MainApplication.Properties.Resources.DL_Coordinate2); private static BitmapImage GetImageIcon(System.Drawing.Bitmap bitmap) { BitmapImage bitmapImage = new Bitmap

更改控件中DrawableLeft图片的大小,图片与文字的距离

Drawable drawable=getResources().getDrawable(R.drawable.xx); //获取图片 drawable.setBounds(left, top, right, bottom);  //设置图片参数 xx.setCompoundDrawablesRelativeWithIntrinsicBounds(null,all,null,null);  //设置到哪个控件的位置() 图片与文字距离 :属性android:drawablePadding="&q

Winform - 判断GroupBox控件中的TextBox文本框是不是为空

foreach (Control item in this.groupBox2.Controls) { if (item is TextBox) { if (item.Text.Trim() == "") { MessageBox.Show("文本框不能为空!", "提示"); return; } } }

Panel控件的使用

我们对控件进行分组的原因不外乎三个: 1.为了获得清晰的用户界面而将相关的窗体元素进行可视化分组. 2.编程分组,如对单选按钮进行分组. 3.为了在设计时将多个控件作为一个单元来移动. 在vb.net中,有GroupBox.Panel.TabControl这三个控件可以实现上面所提到的三个分组目的,所以我们称它们为分组控件. 前面我们了解了GroupBox(控件组)控件(vb.net入门——分组控件:GroupBox控件的使用)的使用,这里我们将来看看下怎么使用Panel(也称面板)控件.实际上

winform上控件太多,绘制时会逐个出现,通常说双缓冲能解决但实际不能解决的问题的解决方法。

protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } 接着找办法解决500多个控件PAINT缓慢的效能问题,心塞.分类都不想分了,就这样. winform上控件太多,绘制时会逐个出现,通常说双缓冲能解决但实际不能解决的问题的解决方法.,布布扣,bubuko.com

Winform状态栏控件中Label靠右显示的方法

设计器: 代码: 在Form_Load事件中添加 : statusStripMain.LayoutStyle= ToolStripLayoutStyle.HorizontalStackWithOverflow; lbl单位.Alignment = ToolStripItemAlignment.Right; lblCompany.Alignment = ToolStripItemAlignment.Right; lbl联系电话.Alignment = ToolStripItemAlignment.

解决Select2控件不能在jQuery UI Dialog中不能搜索的bug

本文使用博客园Markdown编辑器进行编辑 1.问题呈现 项目中使用了jQuery UI的Dialog控件,一般用来处理需要提示用户输入或操作的简单页面.逻辑是修改一个广告的图片和标题. 效果截图如下: 使用Select2,主要是因为它支持下拉式搜索.所以在数据稍微多一点,作为搜索选择功能的首选.但是运行出来之后,发现搜索框无法点击.开始想到的index不够大,被其他的元素覆盖了.但是跳转z-index也无法解决.在普通的页面,搜索框是ok的. 2.解决办法 通过Google搜索,发现sele

flexview模板中解决图表控件不能显示的问题

在flexview模板中的baseWidget.as中,填写如下代码: override public function get moduleFactory():IFlexModuleFactory { return FlexGlobals.topLevelApplication.moduleFactory; } flexview模板中解决图表控件不能显示的问题