Super slow C# custom control(超慢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#自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:超慢C#自定义控件
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01