解决C#中ListView闪烁的办法

解决C#中ListView闪烁的办法

 

在项目中使用ListView演示数据的变化过程, 发现闪烁得太厉害了, Google并综合对比后, 发现下面的方法比较简单且有效, 记录一下:

 1     internal class ListViewNeverFlickering : System.Windows.Forms.ListView
2 {
3 public ListViewNeverFlickering()
4 {
5 // Activate double buffering
6 this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
7
8 // Enable the OnNotifyMessage event so we get a chance to filter out
9 // Windows messages before they get to the form's WndProc
10 this.SetStyle(ControlStyles.EnableNotifyMessage, true);
11 }
12
13 protected override void OnNotifyMessage(Message m)
14 {
15 //Filter out the WM_ERASEBKGND message
16 if (m.Msg != 0x14)
17 {
18 base.OnNotifyMessage(m);
19 }
20 }
21 }

 

参考地址: http://stackoverflow.com/questions/442817/c-sharp-flickering-listview-on-update

posted @ 2012-01-29 16:52  ascrat  阅读(1363)  评论(0编辑  收藏  举报