Populating a FlowLayoutPanel with a large number of controls and painting thumbnails on demand

I'm trying to make an ImageListBox kind of control that will display 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 UserControls, 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:

  1. It seems that WinForms will trigger a Paint event even if the UserControl is not in view. Only 10 or so controls are in fact in view, the rest are not in view (the FlowLayoutPanel.AutoScroll is set to true). As a result, it tries to retrieve thumbnails for ALL the images and that takes a long time...
  2. Adding the UserControls to the FlowLayoutPanel takes 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();

Any help is very much appreciated, thank you.

-------------Problems Reply------------

To improve the speed of populating the FlowLayoutPanel with your user controls, disable layout updating while you add the controls.

Immediately before your loop, call SuspendLayout() and then at the end call ResumeLayout(). Make sure to use a try-finally to guarantee the ResumeLayout() runs even if an exception occurs.

I wouldn't add that many user controls. Rather, I'd have a series of data structures that stores information about what thumbnail to use, positioning, etc, etc, and then handle the rendering of each thumbnail required.

Of course, you would only render what you need, by checking the paint event args in your control and rendering the thumbnails that are in view and that require rendering.

Aha! I found something.

When the UserControl is not in view and it receives a Paint event, then e.ClipRectangle.IsEmpty is true!

Category:c# Views:1 Time:2009-01-22

Related post

  • How to load large number of controls in Canvas selectively 2012-01-28

    I have a big size Canvas and a lot of small user controls placed over it. At a time only a small portion of the canvas is visible on screen. The usercontrols are created by the ItemsControl which is Data bound to a ViewModel. <Canvas Height="10000

  • How to avoid a large number of user controls on a form 2011-06-15

    I'm creating a user control that represents a list of other custom controls (they are pretty simple: include label, checkbox, icon and button). When I place it on a form it takes to long to load all of the list items (there are 100 - 150 items in a l

  • ASP.Net Textbox value lost during postback when you have a very large number of Textboxes on page 2012-02-24

    I have an ASP.NET page where I dynamically create over 1000 textboxes. The initial creation and display of the page works fine, however when I do a posback I find that the control state (Text) is only restored for the first 997 textboxes. The Text pr

  • Multithreading a large number of web requests in c# 2010-11-25

    I have an program where I need to create some large number of folders to an external sharepoint site (external meaning I can't use the sharepoint object model). Web requests work well for this, but simply doing them one at a time (send request, wait

  • How do I handle a large number of properties that initialize a class? 2011-05-26

    I have a class that requires a large number of properties for initialization: Hand hand = new Hand(); hand->skinColor(Color(0.5, 0.5, 0.2)); hand->indexFingerLength(0.5); hand->middleFingerLength(0.6); hand->ringFingerLength(0.55); ... ha

  • Android gridview : error while displaying large number of images 2011-07-01

    I have a grid view which is populated using a custom ImageAdapter class extending BaseAdapter. The images are dynamically loaded from a particular folder in the SD card. I have named the images according to their postition (1.png, 2.png etc.). I have

  • How well will WCF scale to a large number of client users? 2008-09-04

    Does anyone have any experience with how well web services build with Microsoft's WCF will scale to a large number of users? The level I'm thinking of is in the region of 1000+ client users connecting to a collection of WCF services providing the bus

  • Does SQL Server 2005 scale to a large number of databases? 2008-09-15

    If I add 3-400 databases to a single SQL Server instance will I encounter scaling issues introduced by the large number of databases? --------------Solutions------------- This is one of those questions best answered by: Why are you trying to do this

  • Managing authorized_keys on a large number of hosts 2008-09-16

    What is the easiest way to manage the authorized_keys file for openssh across a large number of hosts? If I need to add or revoke a new key to an account on 10 hosts say, I must login and add the public key manually, or through a clumsy shell script,

  • Best approach for redirecting a large number of old URLs to new URLs? 2008-10-28

    We are re-platforming for a client, and they are concerned about SEO. Their current site supports SEO friendly URLs, and so does the new platform. So for those, we are just going to create the same URL mapping. However, they have a large number of ot

  • Store large number of data points? 2008-11-01

    What is the best way to store a large number of data points? For example temperature values which are measured every minute over lots of locations? SQL databases with one row per data points doesn't seem very efficient. --------------Solutions-------

  • ActiveMQ throws OOME when creating a large number of topics 2008-12-18

    I'm using ActiveMQ 5.2 and my application requires a large number of topics, somewhere in the neighbourhood of 500,000. When I run my application, after creating only about 1000 topics, ActiveMQ throws an OutOfMemoryException. Is it unreasonable to e

  • Selecting a large number of rows given the primary key 2009-01-18

    I need to select a large number of rows from an even larger table which is keyed on an autoincrement identity column. I have the primary key values for each of the rows that I'm trying to select, but it could be very large. Often, but not always, the

  • What's the fastest way to test the validity of a large number of well-formed URLs 2009-02-18

    My project requires me to validate a large number of web URLs. These URLs have been captured by a very unreliable process which I do not control. All of the URLs have already been regexp validated and are known to be well-formed. I also know that the

  • Keep a large number of objects in memory for a long time 2009-02-19

    In my ASP.NET app, I have a dictionary that contains a large number of objects (let's say as large as 1M, could get even bigger later), the object stored in the dictionary is of reference type not struct type, the dictionary is meant to work as a cac

  • ASP.Net - Good UI Design Question for Managing large number of items 2009-02-23

    We're currently working on a solution that involves managing a large number of parts for a project. In our database, we have a project table and we have a parts table. Those parts can be assigned to multiple projects and vise-versa. This is done thro

  • Best approach to separate and re-factor a large number of dependent classes 2009-03-05

    I have a v-large number of hierarchical structures (or DTO's) that are shared across different business logic, application tiers, web service and WCF contracts. I want to refactor all of my code to split the structures into discreet business domain a

  • Best way to keep a large number of hobby projects alive; open sourcing? 2009-03-08

    Because my time is limited I can usually only focus on one or two of my hobby projects, while the others sit there wasting away. I am looking for a solution that would allow me to divide my time better. is open sourcing where I take the role of guidi

  • What is the fastest way to read a large number of small files into memory? 2009-03-09

    I need to read ~50 files on every server start and place each text file's representation into memory. Each text file will have its own string (which is the best type to use for the string holder?). What is the fastest way to read the files into memor

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.569 (s). 11 q(s)