Home
Search
ImageList Use: Windows FormsUse the ImageList control in Windows Forms to store images for other controls.
C#
This page was last reviewed on Oct 5, 2022.
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 tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Oct 5, 2022 (edit).
Home
© 2007-2022 sam allen.
see site info on the changelog.