C# 中DataGridView闪烁问题的解决方法
一、DataGridView闪烁问题,开启双缓冲并继承
#region @bobo 窗体刷新防抖动
class DataGridViewForWs : DoubleBufferDataGridView
{
protected override void OnPaint(PaintEventArgs e)
{
try
{
base.OnPaint(e);
}
catch
{
Invalidate();
}
}
}
public class DoubleBufferDataGridView : DataGridView
{
public DoubleBufferDataGridView()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}
#endregion
二、在窗体的Demo.Designer.cs界面,DataGridView继承DataGridViewForWs
DGV_DataShow是DataGridView的(Name)属性
Demo是项目名称
闪烁的DataGridView都可以这样继承
this.DGV_DataShow= new Demo.DataGridViewForWs();