C#开发中listView加载数据闪烁
1.写一个新的listView类继承于原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); } } }
2.在声明的时候,进行类名的替换
修改我们的Form代码中定义ListView的位置
private System.Windows.Forms.ListView listView7;
改为
private ListViewNF listView7;