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)
[Necromantic mode = ON]
You have 1000 row of data, but you only can show a few of them, so create only the controls that will be visible, and reuse them changing its content with the new data when you scroll.
Try this; drop this method in your code.
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } }
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.
You'll have to post some of the layout code or we won't be able to help much/at all.
Also, your #1 best bet is to profile your code. Profiling is the only surefire way to find out what exactly is performing slowly in your code. In my experience, this is especially true of UI code.
The layout logic required for 5k controls will be too much for any type of wrapping panel. You might want to look into a different type of control designed the hold thousands of entries - something like a DataGridView.
The DataGridView has several different column types available that should work for the type of data you're displaying (images, buttons, labels). Since your database query looks to return a DataTable, you could simply bind that directly to your DataGridView and remove the loop.
At 1000+ buttons your probably running perilously low on GDI resources and/or raw handles for your application.
Not sure what your application is supposed to do but a grid or a combo box may be the better option here.