C#使用ListView更新数据出现闪烁解决办法

在使用vs自动控件ListView控件时候,更新里面的部分代码时候出现闪烁的情况

如图:

解决以后:

解决办法使用双缓冲:添加新类继承ListView 对其重写

 public class DoubleBufferListView : ListView
{
public DoubleBufferListView()
{
SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}

新建一个DemoTest测试

1.添加一个DoubleBufferListView的实例

       DoubleBufferListView doubleBufferListView1= new DoubleBufferListView();
//
// doubleBufferListView1
//
this.doubleBufferListView1.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.doubleBufferListView1.FullRowSelect = true;
this.doubleBufferListView1.HideSelection = false;
this.doubleBufferListView1.Location = new System.Drawing.Point(, );
this.doubleBufferListView1.Name = "doubleBufferListView1";
this.doubleBufferListView1.Size = new System.Drawing.Size(, );
this.doubleBufferListView1.TabIndex = ;
this.doubleBufferListView1.UseCompatibleStateImageBehavior = false;
this.doubleBufferListView1.View = System.Windows.Forms.View.Details;

2.将其添加到form窗体里面

 this.Controls.Add(this.doubleBufferListView1);

3.给添加列

        doubleBufferListView1.Clear();
doubleBufferListView1.Columns.Add("Action", , System.Windows.Forms.HorizontalAlignment.Left);
doubleBufferListView1.Columns.Add("value", , System.Windows.Forms.HorizontalAlignment.Right);
doubleBufferListView1.Columns.Add("Action", , System.Windows.Forms.HorizontalAlignment.Left);
doubleBufferListView1.Columns.Add("value", , System.Windows.Forms.HorizontalAlignment.Left);

4.随便添加点内容

         string[] listViewData = new string[];
listViewData[] = "Action";
listViewData[] = "";
listViewData[] = "Action";
listViewData[] = "";
ListViewItem lvItem = new ListViewItem(listViewData, );
doubleBufferView1.Items.Add(lvItem);

5.点击按钮开始运行

 private void button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(PlayGame);
if (state == false)
{
state = true;
button1.Text = "停止";
th.IsBackground = true;
th.Name = "新线程";
th.Start();
}
else
{
state = false;
button1.Text = "开始"; }
}
private void PlayGame()
{
Random r = new Random();
while (state)
{
string temp = r.Next(, ).ToString();
label1.Text = temp;
this.doubleBufferListView1.Items[].SubItems[].Text = temp;
}
}

6.运行对比图:

左侧是解决闪屏后,右侧是自带的ListView效果

C#使用ListView更新数据出现闪烁解决办法的更多相关文章

  1. #使用ListView更新数据出现闪烁解决办法

    //使用双缓冲:添加新类继承ListView 对其重写 public class DoubleBufferListView : ListView { public DoubleBufferListVi ...

  2. (转)Maven依赖的jar包下载不了、jar更新不了的解决办法

    场景一: 使用Maven的同学可能偶尔会遇到这种情况:pom.xml中依赖了项目需要的某个jar文件,但是使用Maven –> update project 还是没办法下载该jar到项目中,你可 ...

  3. 360或者金山毒霸可能会导致HP网络打印机驱动安装失败“数据无效”的解决办法

    360或者金山毒霸可能会导致HP网络打印机驱动安装失败“数据无效”的解决办法     同事办公室的打印机是网线接口的那种网络打印机,不是直接连到电脑的那种,他电脑安装了360和金山毒霸,WIN10下安 ...

  4. ORACLE数据删除数据删除的解决办法

    今天主要以oracle数据库为例,介绍关于表中数据删除的解决办法.(不考虑全库备份和利用归档日志)删除表中数据有三种方法:·delete(删除一条记录)·drop或truncate删除表格中数据 1. ...

  5. hive数据倾斜的解决办法

    数据倾斜是进行大数据计算时常见的问题.主要分为map端倾斜和reduce端倾斜,map端倾斜主要是因为输入文件大小不均匀导致,reduce端主要是partition不均匀导致. 在hive中遇到数据倾 ...

  6. discuz论坛后台部分设置更改之后,清除了缓存网站前台不更新不生效的解决办法

    discuz论坛后台部分设置更改之后,清除了缓存但网站前台不更新不生效的解决办法 在config/config_global.php  把  $_config['memory']['eaccelera ...

  7. SQL Server跨库复制表数据错误的解决办法

    SQL Server跨库复制表数据的解决办法   跨库复制表数据,有很多种方法,最常见的是写程序来批量导入数据了,但是这种方法并不是最优方法,今天就用到了一个很犀利的方法,可以完美在 Sql Serv ...

  8. Android SDK Manager更新不了的解决办法

    android SDK Manager更新不了,出现错误提示:"Failed to fetch URL..."! 可以用以下办法解决: 使用SDK Manager更新时出现问题 F ...

  9. Android SDK及ADT更新访问问题的解决办法

    一.访问问题Eclipse使用SDK Manager更新时总是出现问题 Failed to fetch URL https://dl-ssl.google.com/android/repository ...

随机推荐

  1. nodejs querystring参数处理

    在node js z中,用querystring来进行客户端与服务器的数据交换时序列化数据,是数据处理的小利器. 如:在node中执行这个命令:querystring.stringify({numbe ...

  2. Spring Boot中的事务管理

    原文  http://blog.didispace.com/springboottransactional/ 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数据读写的多步操作的结合 ...

  3. Arcgis, ArcEngine, Arcgis Server使用开发汇总 索引

    ArcGIS系列软件license及安装: Arcgis SDE10.1 和 Arcgis server10.1的授权文件license tnt_esri.dat Arcgis8.1安装license ...

  4. python版本随意切换之python2.7+django1.8.7+uwsgi+nginx源码包部署。

    资源准备: wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz wget https://www.djangoproject ...

  5. spring jdbc 查询结果返回对象、对象列表

    首先,需要了解spring jdbc查询时,有三种回调方式来处理查询的结果集.可以参考 使用spring的JdbcTemplate进行查询的三种回调方式的比较,写得还不错. 1.返回对象(queryF ...

  6. Android之弹出/隐藏系统软键盘

    Android弹出/隐藏系统软键盘的代码如下: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT ...

  7. Selector

    原文: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/Sele ...

  8. html5 Websockets development guidance

    1. WebSockets -- full-duplex communication The main HTML5 pillars include Markup, CSS3, and JavaScri ...

  9. IIS7.0发布Web服务器0002

    asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler” 分类: BS学 ...

  10. python 文件操作(转)

    python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 返回指定目录下的所有文件和目 ...