码迷,mamicode.com
首页 > 其他好文 > 详细

ListView防闪烁

时间:2016-09-17 07:02:17      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

朋友,你的C# ListView是否像霓虹灯一样闪烁?直到眼花缭乱?
看过来吧,ListViewNF是你的对症良药!
只需几句话,你的视界将如此不同!

1、新建一个C# 类,命名为ListViewNF(NF=Never/No Flickering)
2、复制如下代码
class ListViewNF : System.Windows.Forms.ListView
{
   public ListViewNF()
   {
     // Activate double buffering
     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);
     }
   }
}
3、完成
修改你的WinForm对应的xxxx.Design.cs,将系统默认生成的System.Windows.Forms.ListView改为ListViewNF即可。

祝好运!

ListView防闪烁

标签:

原文地址:http://www.cnblogs.com/fuhua/p/5877805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!