描述:拉动DataGridView滚动条时会出现闪烁,看起来像是在重画,感觉不是很好。
解决方式:采用双缓存机制,在方案中添加方法。
代码:
public static class ExtensionMethods
{
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
如果是使用DotNetBar的DatagridviewX控件
public static class DoubleBuffered
{
public static void DoubleBuffered(DataGridViewX dgv,bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",BindingFlags.Instance|BindingFlags.NonPublic);
pi.SetValue(dgv,setting,null);
}
}