Yur*_*riy 18 .net datagridview paint repaint winforms
(抱歉英文不好)
我重新涂漆时的性能存在很大问题DataGridView.
我正在使用a DataGridView来显示来自外部应用程序流的日志.来自流的消息以高频率(小于1毫秒)进入.如果我DataGridView在每条新消息到来时立即添加新行,DataGridView则在下一条消息到来之前没有时间重新绘制自己.
一种可能的解决方案是使用队列来收集消息,并使用队列中的消息DataGridView每100毫秒重新绘制一次.这很好但是DataGridView当它自动滚动到最后一行时闪烁.(禁用平滑滚动)
你能帮助我改善DataGridView表现吗?
dan*_*n78 43
我最近有一些缓慢的问题,DataGridView解决方案是以下代码
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);
}
Run Code Online (Sandbox Code Playgroud)
它会对DataGridView对象进行双缓冲.只需打电话DoubleBuffered()给你的DGV.希望能帮助到你.
编辑:我可能已经把它关闭了,但我现在无法搜索原文,所以这只是为了强调代码不是我的.
没有反射的清洁溶液是:
public class DataGridViewDoubleBuffered : DataGridView
{
public DataGridViewDoubleBuffered()
{
DoubleBuffered = true;
}
}
Run Code Online (Sandbox Code Playgroud)
然后转到myForm.designer.cs并将类型从DataGridView更改为DataGridViewDoubleBuffered.