카테고리 없음
[씨#] Windows 7에서 C # Winform 그리드 렌더링이 느림
행복을전해요
2020. 12. 11. 10:30
그리드에 대한 모든 이벤트 핸들러를 비활성화 한 다음 그리드의 성능을 확인하십시오. 제대로 작동하면 성능이 저하 될 때까지 일부를 활성화하십시오. 그리드에 대한 이벤트 처리기가없고 여전히 느리게 수행되는 경우에도 Steve가 그의 답변에서 언급 한대로 AutoSizing이 원인 일 수 있습니다.
다른 시스템에서 애플리케이션 성능이 저하됩니까? 다시 설치해야하는 비디오 드라이버와 관련된 것일 수 있습니까?
편집 : 방금 테스트 응용 프로그램을 만들고 문제를 보았지만 이중 버퍼링을 수행하면 사라 졌습니까? 이중 버퍼링은 어떻게 했습니까?
이 대답을 참조하십시오 : 양식에서 .NET 컨트롤을 두 번 버퍼링하는 방법은 무엇입니까?
내 전체 코드는 DataSet
라는 20 개의 열로 DataSet1
만든 다음 다음과 같이 간단한 Windows Form을 만들었습니다 DataGridView
.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// comment out the line below for the application to lag
SetDoubleBuffered(dataGridView1);
for (int i = 0; i < 10000; i++)
{
dataSet1.DataTable1.AddDataTable1Row(GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString(),
GetRandomString());
}
}
public static void SetDoubleBuffered(System.Windows.Forms.Control c)
{
//Taxes: Remote Desktop Connection and painting
//http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx
if (System.Windows.Forms.SystemInformation.TerminalServerSession)
return;
System.Reflection.PropertyInfo aProp =
typeof(System.Windows.Forms.Control).GetProperty(
"DoubleBuffered",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
aProp.SetValue(c, true, null);
}
private Random rand = new Random();
private string validChars = "0123456789abcdefghijklmnopqurstuvwyz";
private string GetRandomString()
{
StringBuilder builder = new StringBuilder();
char[] c = new char[rand.Next(15,20)];
for (int i = 0; i < c.Length; i++)
{
c[i] = validChars[rand.Next(0, validChars.Length - 1)];
}
return new string(c);
}
}
}
각각 15-20에서 다양한 길이의 20 개 열이있는 100,000 개 이상의 레코드로 테스트되었습니다.
-------------------AutoSizeRowsMode 및 AutoSizeColumnsMode 설정을 확인할 수 있습니다.
때때로 AutoSizing으로 인해 GUI가 느려질 수 있습니다.
출처
https://stackoverflow.com/questions/7415016