C#使用ListView更新数据出现闪烁解决办法
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更新数据出现闪烁解决办法的更多相关文章
- #使用ListView更新数据出现闪烁解决办法
//使用双缓冲:添加新类继承ListView 对其重写 public class DoubleBufferListView : ListView { public DoubleBufferListVi ...
- (转)Maven依赖的jar包下载不了、jar更新不了的解决办法
场景一: 使用Maven的同学可能偶尔会遇到这种情况:pom.xml中依赖了项目需要的某个jar文件,但是使用Maven –> update project 还是没办法下载该jar到项目中,你可 ...
- 360或者金山毒霸可能会导致HP网络打印机驱动安装失败“数据无效”的解决办法
360或者金山毒霸可能会导致HP网络打印机驱动安装失败“数据无效”的解决办法 同事办公室的打印机是网线接口的那种网络打印机,不是直接连到电脑的那种,他电脑安装了360和金山毒霸,WIN10下安 ...
- ORACLE数据删除数据删除的解决办法
今天主要以oracle数据库为例,介绍关于表中数据删除的解决办法.(不考虑全库备份和利用归档日志)删除表中数据有三种方法:·delete(删除一条记录)·drop或truncate删除表格中数据 1. ...
- hive数据倾斜的解决办法
数据倾斜是进行大数据计算时常见的问题.主要分为map端倾斜和reduce端倾斜,map端倾斜主要是因为输入文件大小不均匀导致,reduce端主要是partition不均匀导致. 在hive中遇到数据倾 ...
- discuz论坛后台部分设置更改之后,清除了缓存网站前台不更新不生效的解决办法
discuz论坛后台部分设置更改之后,清除了缓存但网站前台不更新不生效的解决办法 在config/config_global.php 把 $_config['memory']['eaccelera ...
- SQL Server跨库复制表数据错误的解决办法
SQL Server跨库复制表数据的解决办法 跨库复制表数据,有很多种方法,最常见的是写程序来批量导入数据了,但是这种方法并不是最优方法,今天就用到了一个很犀利的方法,可以完美在 Sql Serv ...
- Android SDK Manager更新不了的解决办法
android SDK Manager更新不了,出现错误提示:"Failed to fetch URL..."! 可以用以下办法解决: 使用SDK Manager更新时出现问题 F ...
- Android SDK及ADT更新访问问题的解决办法
一.访问问题Eclipse使用SDK Manager更新时总是出现问题 Failed to fetch URL https://dl-ssl.google.com/android/repository ...
随机推荐
- linux shell 用sed命令在文本的行尾或行首添加字符
转自 http://www.cnblogs.com/aaronwxb/archive/2011/08/19/2145364.html 昨天写一个脚本花了一天的2/3的时间,而且大部分时间都耗在了sed ...
- unsilder中的jq深入学习
//trigger $('#foo').on('click', function() { alert($(this).text()); }); $('#foo').trigger('click'); ...
- Android中仿IOS提示框的实现
前言 在Android开发中,我们有时需要实现类似IOS的对话框.今天我就来总结下,如何通过自定义的开发来实现类似的功能. 自定义Dialog 我们知道Android中最常用的对话框就是Dialog及 ...
- ruby 基础知识三 读写文件
1.File 中参数的含义 r 只读模式.文件指针被放置在文件的开头.这是默认模式. r+ 读写模式.文件指针被放置在文件的开头. w 只写模式.如果文件存在,则重写文件.如果文件不存在,则创建一个新 ...
- 3.1、Spring和Struts2的结合使用
一.配置Struts2: 1.新建一个web项目,在src目录下新建com.st.bean/dao/service/action包,并在该包下面添加相应的接口及接口的实现类: a).在bean下新建一 ...
- sessionState详解
asp.net Session的默认时间设置是20分钟,即超过20分钟后,服务器会自动放弃Session信息. 当我们在asp.net程序中打开web.config的时候,可以看到一段如下的代码: A ...
- 通过JAVA程序测试闰年
首先简要介绍一下公历上规定的闰年:四年一闰,百年不闰,四百年再闰. 针对这一规则,简要的设计部分测试用例: 附(测试截图): 以下为该程序代码段: import javafx.application. ...
- c语言经典算法——查找一个整数数组中第二大数
题目: 实现一个函数,查找一个整数数组中第二大数. 算法思想: 设置两个变量max1和max2,用来保存最大数和第二大数,然后将数组剩余的数依次与这两个数比较,如果这个数a比max1大,则先将max1 ...
- Javascript设计模式学习二(单例)
定义:保证一个类仅有一个实例,并提供一个访问它的全局访问点 普通的单例模式: 使用一个变量来标记当前是否已经为某个类创建过对象,如果是的话,在下一次获取该类的实例时,直接返回之前创建的对象.比如:使用 ...
- 基于Spring AOP的JDK动态代理和CGLIB代理
一.AOP的概念 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的 ...