超慢C#自定义控件

Super slow C# custom control(超慢C#自定义控件)
本文介绍了超慢C#自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个自定义控件,它是一个 FlowLayoutPanel,我在其中放入了一堆其他自定义控件(只是按钮,每个都有三个标签和一个图片框覆盖)

I've made a custom control, it's a FlowLayoutPanel, into which I put a bunch of other custom controls (just Buttons, each with three Labels and a PictureBox overlayed)

大约 100 个按钮可以正常工作,但如果增加到 1000 个按钮,就会遇到麻烦.将其提高到 5000,它会在 20 秒后死亡.

It works ok with around 100 buttons, but bump that up to 1000 and it's in trouble. Bump that up to 5000 and it just dies after 20 seconds.

我的自定义代码很少,我明智地使用了暂停和恢复布局.

I have very little custom code, and I make judicious use of suspend and resume layout.

那我做错了什么?我确信我的(相当快速的)计算机应该能够处理几千个按钮和标签.

So what am I doing wrong? I'm sure my (fairly rapid) computer should be able to handle a few thousand buttons and labels.

(我对 C# GUI 的东西还很陌生,所以也许我应该做一些完全不同的事情.)

(I'm fairly new to C# GUI stuff, so perhaps I should be doing things completely different anyway.)

编辑 1:

这几乎是目前唯一的自定义代码:

This is pretty much the only custom code at the moment:

flowLayoutPanel1.SuspendLayout();
foreach (DataRow row in dt.Rows) // dt is from a DB query
{
    flowLayoutPanel1.Controls.Add(new PersonButton(row));
}
flowLayoutPanel1.ResumeLayout();

在 PersonButton 构造函数中:

and in the PersonButton constructor:

this.label1.Text = row["FirstName"].ToString().Trim() + " "
    + row["Surname"].ToString().Trim();

(应该还附上一张图片,但我不确定是否有人能看到.)

(There should also be a picture attached but I'm not sure if anyone can see it.)

编辑 2:

我想我真的应该使用 DataGridView 或 ListView,但我想要的不仅仅是一行文本和每行一个小图标;我希望它看起来类似于 Firefox 中的下载视图(Ctrl + J).(见截图)

I guess I really should be using a DataGridView, or ListView, but I wanted more than just a line of text and a small icon per row; I wanted it to look similar to the downloads view in firefox (Ctrl + J). (See screenshot)

非常感谢您的所有意见,顺便说一句.我想我得重新考虑......

Thanks very much for all your input, BTW. I guess I'll have to rethink...

替代文字 http://img156.imageshack.us/img156/1057/capture.png

推荐答案

C# WinForm 应用程序可以处理 1000 个任何类型控件的实例吗?我不是 WinForm Guru,但您对您的应用程序的期望可能是不合理的.

Can a C# WinForm app handle 1000 instances of any type of control? I am no WinForm Guru, but what you are expecting from your application might be unreasonable.

您想要显示 1000 多个任何类型的控件这一事实可能表明您正在从错误的方向进行软件设计.

The fact that you want to show 1000+ controls of any type might be a sign that you are approaching the design of your software from the wrong direction.

这篇关于超慢C#自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)