C#中使用ListView动态添加数据不闪烁
2015-10-19 13:52
721 查看
首先,自定义一个类ListViewNF,继承自 System.Windows.Forms.ListView
class ListViewNF : System.Windows.Forms.ListView
{
public ListViewNF()
{
// 开启双缓冲
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint,
true);
// Enable the OnNotifyMessage event so we get a chance to filter out
// Windows messages before they get to the form's WndProc
this.SetStyle(ControlStyles.EnableNotifyMessage,
true);
}
protected override
void OnNotifyMessage(Message m)
{
//Filter out the WM_ERASEBKGND message
if (m.Msg !=
0x14)
{
base.OnNotifyMessage(m);
}
}
}
然后,修改我们的Form代码中定义ListView的位置,将原来的
System.Windows.Forms.ListView listView1;
修改为
ok,然后随便怎么insert\add这个listView1,都不会有半点的闪烁了.
class ListViewNF : System.Windows.Forms.ListView
{
public ListViewNF()
{
// 开启双缓冲
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint,
true);
// Enable the OnNotifyMessage event so we get a chance to filter out
// Windows messages before they get to the form's WndProc
this.SetStyle(ControlStyles.EnableNotifyMessage,
true);
}
protected override
void OnNotifyMessage(Message m)
{
//Filter out the WM_ERASEBKGND message
if (m.Msg !=
0x14)
{
base.OnNotifyMessage(m);
}
}
}
然后,修改我们的Form代码中定义ListView的位置,将原来的
System.Windows.Forms.ListView listView1;
修改为
ListViewNF listView1;
ok,然后随便怎么insert\add这个listView1,都不会有半点的闪烁了.
相关文章推荐
- C#文件写入
- C#时间戳
- C#委托的介绍(delegate、Action、Func、predicate)
- C#学习日记26---接口(interface)类型
- 使用C#和Thrift来访问Hbase实例
- C#基础巩固(2)-Linq To XML创建XML
- C# 5.0 与 .Net 4.5 学习(一)Race Conditions资源竞争
- C#可以自动在后台为属性创建字段
- C#.NET里面抽象类和接口有什么区别
- 利用序列化的方式实现C#深复制和浅复制
- C#线程并发执行的实例[转]
- C# 可否对内存进行直接的操作?
- c#子线程调用主线程控件
- AX2009 C#客户端通过Web service批量审核工作流(一)
- (原创)c#学习笔记03--变量和表达式04--表达式04--命名空间
- 猴子选大王——CSharp数组
- C#面向对象设计模式纵横谈——3.Abstract Factory 抽象工厂(创建型模式)
- C#读写(OFFICE 2013)excel表格(续)
- (原创)c#学习笔记03--变量和表达式04--表达式03--运算符的优先级
- C#运算符重载和索引器