I'm trying to make an ImageListBox kind of control that will display a large numbers of thumbnails, like the one that Picasa uses.
This is my design:
I have a FlowLayoutPanel that is populated with a lot of UserControl objects, for example 4,000.
Each UserControl is assigned a delegate for the Paint event.
When the Paint event is called, it checks a memory cache for the thumbnail and if the image is not in cache, it retrieves it from the disk.
I have two problems that I'm trying to solve:
It seems that WinForms will trigger a
Paintevent even if theUserControlis not in view. Only 10 or so controls are in fact in view, the rest are not (theFlowLayoutPanel.AutoScrollis set totrue). As a result, it tries to retrieve thumbnails for all the images and that takes a long time.Adding the
UserControlobjects to theFlowLayoutPaneltakes a somewhat long time, about 2-3 seconds. I can live with it but I'm wondering if there is a better way to do it than:UserControl[] boxes = new UserControl[N]; // populate array panel.SuspendLayout(); panel.Controls.AddRange(boxes); panel.ResumeLayout();