Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Super slow C# custom control

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)

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.

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

Edit 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();

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

Edit 2:

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

alt text http://img156.imageshack.us/img156/1057/capture.png

like image 813
aidan Avatar asked Aug 21 '26 04:08

aidan


1 Answers

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.

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.

like image 119
Matthew Ruston Avatar answered Aug 23 '26 11:08

Matthew Ruston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!