ImageList Control
The ImageList is a non-visual component that stores images for other controls like ListView, TreeView, and ToolStrip.
What is an ImageList?
ImageList doesn't appear on your form - it's a component that stores images in memory. Other controls use it to display icons. This saves memory and makes it easy to share images across multiple controls.
How to Use
- Drag an ImageList component onto your form (it appears in the component tray).
- Click the Images property to open the Image Collection Editor.
- Add images (PNG, ICO, JPG, BMP).
- Set ImageSize property (16x16, 32x32, etc.).
- Assign to controls like ListView's SmallImageList or LargeImageList.
Code Example
// Add images to ImageList programmatically
imageList1.ImageSize = new Size(32, 32);
imageList1.Images.Add(Image.FromFile("icon1.png"));
imageList1.Images.Add(Image.FromFile("icon2.png"));
imageList1.Images.Add(Image.FromFile("icon3.png"));
// Assign to ListView
listView1.LargeImageList = imageList1;
listView1.Items[0].ImageIndex = 0; // First image
// Or use the ImageKey property
listView1.Items[1].ImageKey = "icon2.png";
Exercise
Task: Create an icon toolbar using ImageList.
- Add an ImageList with 5-8 icons (or use built-in images).
- Add a ToolStrip and set its ImageList property.
- Add ToolStripButtons and set their ImageIndex.
- Add a ListView with SmallImageList and LargeImageList.
- Add items with different icons.
Key Takeaway
ImageList stores images in memory for reuse by multiple controls. It's essential for creating professional-looking applications with icons.