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

问题描述

我已经制作了一个自定义控件,它是一个FlowLayoutPanel,我在其中放置了一堆其他自定义控件(只是按钮,每个按钮都覆盖了三个Label和一个PictureBox)

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.

我的自定义代码很少,并且我明智地使用了suspend和resume布局.

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.)

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

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.)

我想我确实应该使用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#自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:26