C#Winform的电网在Windows 7上呈现缓慢 [英] C# Winform grid rendering slow on Windows 7

查看:180
本文介绍了C#Winform的电网在Windows 7上呈现缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,C#的winform DataGrid的是在我的Windows 7 64位的机器很慢。对于1000行+足够的列/文本的标准网格以适合屏幕的宽度,我看到滚动呈现明显的延迟(即滚动/滚动运动由〜落后0.5秒,而不是光滑)。当最大化为全屏,并得到作为显示尺寸减小较快网格是特别慢。

I noticed that C# winform datagrid is quite slow on my windows 7 64bit machine. For a standard grid with 1000 rows + enough columns/text to fit the width of the screen, I see noticeable rendering delay with scrolling (ie scrolling/scrollbar movement lags by ~0.5 second instead of smooth). The grid is particularly slow when maximized to full screen and gets faster as the display size decrease.

GUI可通过绑定一个DataTable到一个DataGridView实例,一个简单的设置;我看了成常见的罪魁祸首,如双缓冲,并没有看到太多的改进。该机赢得7 64位至强四核和2×23inch上的NVIDIA Quadro NVS 420的屏幕。

The GUI is a straightforward setup by binding a DataTable to a DataGridView instance; I've looked into the common culprits such as double buffering and did not see much improvements. The machine is win 7 64 bit with Xeon quad-core and 2 x 23inch screens on nvidia quadro nvs 420.

任何人有任何想法,为什么发生这种情况?

Anyone have any idea why this is happening ?

推荐答案

尝试禁用所有事件处理程序的网格,然后看电网如何执行。如果执行罚款,使一些,直到你的表现苦难。如果,即使有对电网无事件处理程序,它仍然执行慢的罪魁祸首由史蒂夫在他的答复中提到可能会自动调整大小。

Try disabling all event handlers for the grid and then see how the grid performs. If it performs fine, enable some until you get to the performance suffering. If even when there are no event handlers for the grid and it still performs slow the culprit might be AutoSizing as mentioned by Steve in his answer.

有没有应用程序的性能上的任何受苦其他机器? ?难道是相关的视频驱动程序需要重新安装的东西。

Does application performance suffer on any other machine? Could it be something related to video drivers needing to be re-installed?

编辑:我只是做了一个测试应用程序,看到你的问题,但它走了,当我做双缓冲?
你是怎么做的双缓冲

I just made a test application and saw your problem, but it went away when i did double buffering? how did you do the double buffering?

看到这个答案:
如何在窗体上双缓冲.NET控件?

我的完整的代码,我做了一个的DataSet 20列名为数据集1 ,然后我做了一个简单的Windows窗体与一个 DataGridView的

my full code, I made a DataSet with 20 columns called DataSet1, and then I made a simple Windows Form with a 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);
        }
    }
}

有超过10万的记录每一个测试从15-20

Tested with over 100,000 records each with 20 columns of varying length from 15-20

这篇关于C#Winform的电网在Windows 7上呈现缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆