An ImageList is a supporting control that is typically used by other controls, such as a ListView but is exposed as a component to developers. We can use this component in our applications when we are building our own controls such as a photo gallery or an image rotator control.
In this article, I will discuss how to create an ImageList control and how to use its properties and methods to use in a Windows Forms application.
Creating an ImageList
ImageList class represents the ImageList First step to create a dynamic ImageList is to create an instance of ImageList class. The following code snippet creates an ImageList control object.
ImageList photoList = new ImageList();
In the next step, you may set properties of an ImageList control. The following code snippet sets a few properties of an ImageList.
photoList.TransparentColor = Color.Blue;
photoList.ColorDepth = ColorDepth.Depth32Bit;
photoList.ImageSize = new Size(200, 200);
Unlike other Windows Forms control, you can't add ImageList control to a Form. You need to draw an ImageList control using the Draw method. The Draw method takes a Graphics object that is the handle of the container control that will be used as a drawing canvas.
photoList.Draw(g, new Point(20, 20), count);
Setting ImageList Properties
ColorDepth property represents the color depth of the image list.
ImageSize property represents the size of the images in the image list.
Images property represents all images in an ImageList as an ImageCollection object.
The following code snippet sets these properties and adds three images to the ImageList control and later loops through the images and displays them on a Form.
Graphics g = Graphics.FromHwnd(this.Handle);
ImageList photoList = new ImageList();
photoList.TransparentColor = Color.Blue;
photoList.ColorDepth = ColorDepth.Depth32Bit;
photoList.ImageSize = new Size(200, 200);
photoList.Images.Add(Image.FromFile(@"C:\Images\Garden.jpg"));
photoList.Images.Add(Image.FromFile(@"C:\Images\Tree.jpg"));
photoList.Images.Add(Image.FromFile(@"C:\Images\Waterfall.jpg"));
for (int count = 0; count < photoList.Images.Count; count++)
{
photoList.Draw(g, new Point(20, 20), count);
// Paint the form and wait to load the image
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
}
Summary
In this article, we discussed discuss how to create and use an ImageList control in a Windows Forms application.

Abdul Amin KhanPosted Jan 18, 2017, 6:55 AM
Hi Mahesh this code is working fine but when i try to use it with large number of images of high resolution like 200 then it showing "Out of Memory Error". Help me out on this. If you have any other idea about to Show Large number of images like thumbnail view please share that with me. Minimum Image Count is 60, Image Resolution : 200 or more Speed bit faster than now
Trupti RanePosted May 10, 2013, 2:35 AM
nice article ....got what i looking for
Rehan Parvez QureshiPosted Jan 30, 2012, 1:05 PM
Iis server making debug problm.so kindly solutn on [email protected]
Jinal ShahPosted Dec 5, 2011, 7:18 AM
Hi Mahesh It always cool to view your code as it helped me a lot and even at times its the same what i was looking for. Would be glad to make you a friend and hope you would like it too. Looking forward for your reply. Regards
Ei Cho ZinPosted Aug 7, 2010, 1:10 AM
I do as u say. But the images are not shown in Form. Image Path is okay. I want to know why? Please reply me. Thank a lot.
venkat kPosted Jul 20, 2010, 9:15 AM
can u please send me how to create dynamic controls, fetching events and more exampls on dynamic controls plz regards venkat 9502675656