C# 中DataGridView和ListView闪烁问题的解决方法
C# 中DataGridView和ListView闪烁问题的解决方法
方法一
首先定义类,将此类放在datagridview或ListView所在的窗体类外面,然后代码如下,
<span style="font-family:Microsoft YaHei;font-size:18px;">// <summary>
/// 双缓冲DataGridView,解决闪烁
/// 使用方法:在DataGridView所在窗体的InitializeComponent方法中更改控件类型实例化语句将
/// this.dataGridView1 = new System.Windows.Forms.DataGridView(); 屏蔽掉,添加下面这句即可
/// this.dataGridView1 = new DoubleBufferListView();
/// </summary>
class DoubleBufferDataGridView : DataGridView
{
public DoubleBufferDataGridView()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
//UpdateStatus.Continue;
UpdateStyles();
}
}
/// <summary>
/// 双缓冲ListView ,解决闪烁
/// 使用方法是在ListView 所在窗体的InitializeComponent方法中,更改控件类型实例化语句将
/// this.listView1 = new System.Windows.Forms.ListView(); 屏蔽掉, 添加下面语句即可
/// this.listView1 = new DoubleBufferListView();
/// </summary>
class DoubleBufferListView : ListView
{
public DoubleBufferListView()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}</span>
方法二
直接写一个扩展方法,使用反射,直接上代码,将此类定义给DataGirdView或ListView所在的窗体类外面即可
<span style="font-family:Microsoft YaHei;font-size:18px;">public static class DoubleBufferDataGridView
{
/// <summary>
/// 双缓冲,解决闪烁问题
/// </summary>
/// <param name="dgv"></param>
/// <param name="flag"></param>
public static void DoubleBufferedDataGirdView(this DataGridView dgv, bool flag)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, flag, null);
}
}
public static class DoubleBufferListView
{
/// <summary>
/// 双缓冲,解决闪烁问题
/// </summary>
/// <param name="lv"></param>
/// <param name="flag"></param>
public static void DoubleBufferedListView(this ListView lv, bool flag)
{
Type lvType = lv.GetType();
PropertyInfo pi = lvType.GetProperty("DoubleBuffered",
BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(lv, flag, null);
}
}</span>
//调用方法
<span style="font-family:Microsoft YaHei;font-size:18px;">public Form1()
{
InitializeComponent();
DataGridView1.DoubleBufferedDataGirdView(true);
}</span>
其实很简单的,一看代码就能明白,使用双缓冲解决闪烁问题
---------------------
作者:ching126
来源:CSDN
原文:https://blog.csdn.net/chenhongwu666/article/details/43305503
版权声明:本文为博主原创文章,转载请附上博文链接!
C# 中DataGridView和ListView闪烁问题的解决方法的更多相关文章
- WAMP中phpMyAdmin登陆不了问题的解决方法
WAMP中phpMyAdmin登陆不了问题的解决方法
- 问题-[Access]“无法打开工作组信息文件中的表 'MSysAccounts'”的问题的解决方法
问题现象:ado.net oledb方式访问Access数据库文件时报错“无法打开工作组信息文件中的表 'MSysAccounts'”的问题的解决方法 问题处理:1.数据库名称不能命名为:Syste ...
- PHP开发中常见的安全问题详解和解决方法(如Sql注入、CSRF、Xss、CC等
页面导航: 首页 → 网络编程 → PHP编程 → php技巧 → 正文内容 PHP安全 PHP开发中常见的安全问题详解和解决方法(如Sql注入.CSRF.Xss.CC等) 作者: 字体:[增加 减小 ...
- jquery ui中 accordion的问题及我的解决方法
原文:jquery ui中 accordion的问题及我的解决方法 jquery有一套所谓的ui组件,很不错的.如果有兴趣的朋友,可以参考http://jqueryui.com/ 但其中的accord ...
- ASP.NET MVC中对Model进行分步验证的解决方法
原文:ASP.NET MVC中对Model进行分步验证的解决方法 在我之前的文章:ASP.NET MVC2.0结合WF4.0实现用户多步注册流程中将一个用户的注册分成了四步,而这四个步骤都是在完善一个 ...
- JS网站当前日期在IE9、Chrome和FireFox中年份显示为113年的解决方法 getFullYear();
JS网站当前日期在IE9.Chrome和FireFox中年份显示为113年的解决方法 getFullYear();
- 关于CUDA C 项目中“ error C2059: 语法错误:“<” ”问题的解决方法
该问题的关键在于理解CUDA项目中C\C++文件需要由c++编译器进行编译,而CUDA C的源文件需要由CUDA的编译器nvcc.exe进行编译. 发生该语法错误的原因是cu文件被C++编译器所编译, ...
- ios UITableView中Cell重用机制导致内容重复解决方法
UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...
- 如何自定义JSTL标签与SpringMVC 标签的属性中套JSTL标签报错的解决方法
如何自定义JSTL标签 1.创建一个类,从SimpleTagSupport继承 A) 通过继承可以获得当前JSP页面上的对象,如JspContext I) 实际上可以强转为PageContext II ...
随机推荐
- 让虚拟环境解决python多版本并行
一.安装篇 1.本文操作系统为CentOS7 依赖包(安装时可能还存在其他依赖包,结合报错进行安装) [root@Corre home]# yum install make build-essenti ...
- java集合(二)
- java 五十条数据分为一组
public static void main(String[] args) { List<Integer> list = new ArrayList<>(); for(int ...
- sql嵌套查询
嵌套查询的意思是,一个查询语句(select-from-where)查询语句块可以嵌套在另外一个查询块的where子句中,称为嵌套查询.其中外层查询也称为父查询,主查询.内层查询也称子查询,从查询. ...
- IDEAL 热更新
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- nova98 假区域链 骗人项目(vexx.pro的前身)
首先,我是受害者. nova98前期是vexx.pro,前期推广送比特龙, 送3个,然后推广一个新人可以再拿到1.5个. 然后呢,现在就又推出一个新网站,nova98,把之前推广的人领到币全部清零,而 ...
- Linux命令rz
rz :上传文件:sz: 下载文件: 在linux 系统中,使用rz(或 sz) 命令是,提示 -bash: rz(或者是sz): command not found .这个时候,说明没有安装 lrz ...
- TabLayout下划线指示器自适应文字宽度
解决方案1: 更新design库到28.0.0-rc01 implementation 'com.android.support:design:28.0.0-rc01' 然后在TabLayout里设置 ...
- web端分享网页到各个网站JS代码(微信为生成二维码)
/*分享到新浪微博,QQ空间,人人网,生成二维码*/ var myTitle=$("title").text(); var myHref = window.location.hre ...
- Linux环境下安装nginx
#一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩cd /usr/local/devmkdir nginxcd nginxmkdir softcd soft # ...