解决DataGridView拖动闪烁问题

  在开发能源平台的过程中,发现当展示数据量巨大时,横向拖动DataGridView的滑动条会产生严重的闪烁问题影响进而用户体验。

  百度了下,发现只需要为窗体和控件添加双缓冲就能解决问题。

把下面代码放在DataGridView父控件的构造函数中即可:

 //设置窗体的双缓冲
 this.SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);           
 this.UpdateStyles ();
 //利用反射设置DataGridView的双缓冲
 Type dgvType = this.dgvReport.GetType ();           
 PropertyInfo pi = dgvType.GetProperty ("DoubleBuffered",                BindingFlags.Instance | BindingFlags.NonPublic);
 pi.SetValue (this.dgvReport, true, null);

 

posted @ 2019-02-21 11:01  AKA-Green  阅读(772)  评论(0编辑  收藏  举报