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 ...
随机推荐
- 解决nim db_mysql could not load: libmysql.dll的问题
title: 解决nim db_mysql could not load: libmysql.dll的问题 nim中使用db_mysql 操作数据库的代码看起来很简单: import db_mysql ...
- mysql 自定义方法 function
在创建函数的时候,如果报如下错误 这个时候一定要先执行:set global log_bin_trust_function_creators=TRUE; 第二步骤: delimiter ;;CREAT ...
- 【javascript小案例】从0开始实现一个俄罗斯方块
写在前面得话: 这篇文章主要记录了我是怎么一步一步写出俄罗斯方块,整个代码用的函数编程,主要是为了让一些不熟悉es6, 面向对象写法得 新手能更容易看明白,全部得代码中都是一些js的基础知识,很容易理 ...
- Legal or Not ,图的拓扑
ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that just ...
- 前端测试时,常用SQL
与后台联调页面,经常会验证数据正确性,这时候就需要会点SQL语句,以下是常用的SQL: 单表查询 select * from table 条件查询 select * from table where ...
- python(pygame)滑稽大战(类似飞机大战) 教程
成品已录制视频投稿B站(本文目前实现了基础的游戏功能),点击观看项目稽忽悠不(github)地址:https://github.com/BigShuang/From-simple-to-Huaji 本 ...
- iOS利用xcodebuild命令自动打包方法
1,xcode项目先打包试一下可以打包成功 2,创建一plist导出文件 3,xcodebuild命令直接运行 导出文件内容: <?xml version="1.0" enc ...
- 网络请求————ProxyHandler实现代理ip
from urllib import request #这个是没有使用代理的 # resp = request.urlopen('http://httpbin.org/ip') # print(res ...
- golang context
ex1 package main import ( "fmt" ) // 最佳context 实践 // Context 目标是实现各个goroutine能及时终止退出. func ...
- VirtualBox安装Archlinux并配置桌面环境
最近无聊,就找来archlinux来玩一玩,去archlinux wiki上看了一下教程.以下是操作过程. 1. 下载镜像,下载地址; 2. 启动archlinux并选择Boot Arch Linux ...