Updated Oct 5, 2022
Dot Net Perls
ImageList. This control provides a container for image data. It is referenced from other controls such as ListView, which get the images from index values into the ImageList.
Getting started. Please add an ImageList control by double-clicking on the ImageList entry in the Toolbox. It will appear in the tray of the designer at the bottom.
Add images. You can add any image to the ImageList dynamically by invoking the Add method. This method has several overloaded versions and you can call any of them.
Here We have a list of file names, and then add each as an Image object using the Image.FromFile method to read the data.
Info The Form1_Load event handler is used to make sure the code is run at startup of the application.
using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Add these file names to the ImageList on load. string[] files = { "image.png", "logo.jpg" }; var images = imageList1.Images; foreach (string file in files) { // Use Image.FromFile to load the file. images.Add(Image.FromFile(file)); } } } }
ListView. How can we reference an ImageList in other controls such as the ListView? On the ListView, find the LargeImageList and SmallImageList properties.
Then Please select the ImageList instance you created as the value of these properties.
Info You can use the ListView to specify the index of the images inside your ImageList.
ListView
Summary. By providing a container for images, the ImageList control gives Windows Forms programs another level of abstraction for managing images.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Oct 5, 2022 (edit).
Home
Changes
© 2007-2025 Sam Allen