dcsimg

Common .NET Controls Crash Course, Part 4: ImageList

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


Continuing this series, Part 5 talks about the ImageList.

What Is an ImageList?

An ImageList holds images for toolbars, menubars, or any other component making use of many images.

An example of an ImageList in action is shown in Figure 1.

Microsoft Word Toolbar
Figure 1: Microsoft Word Toolbar

You will see that the ImageList can produce many images, all of which depend on the various images you can add and the properties you set.

Using the ImageList

Let's create a Windows Forms application with at least one form. When the form has loaded, you can have a look in the toolbox for the ImageList. The Toolbox is shown in Figure 2.

Toolbox
Figure 2: Toolbox

Once the ImageList has been added, you may notice the Properties window, as shown in Figure 3. This is where we set the ImageList properties.

Properties Window
Figure 3: Properties Window

Let's have a look at some of the properties.

Cool ImageList Properties

The following properties control how the ListBox work and how it appears:

  • ColorDepth
  • Images
  • ImageSize

ColorDepth

The ListBox ColorDepth property determines the number of colors used to display images. The values are:

Depth4Bit 4-bit image Depth8Bit 8-bit image Depth16Bit 16-bit image Depth24Bit 24-bit image Depth32Bit 32-bit image

Images

Gets or sets the collection of images for the ImageList control.

Here is a coding example:

   // Add two images to the list.
      ImageList1.Images.Add(Image.FromFile("c:\\temp\\image1.jpg"));
      ImageList1.Images.Add(Image.FromFile("c:\\temp\\image2.jpg"));

This adds two images to the ImageList.

You also can add images to the collection in Design time by selecting the ellipses button next to the Images property and selecting Add. Figure 4 shows the Add Image dialog box in action.

Add Images
Figure 4: Add Images

ImageSize

The ImageSize property gets or sets the size of the images in the list. The default size (in pixels) is 16 by 16. The maximum size (in pixels) is 256 by 256.

Conclusion

I hope that this article has helped you understand the intricacies of an ImageList. I would love to do more articles on the basics of controls, so hopefully there will be more.



This article was originally published on March 26th, 2020

About the Author

Hannes DuPreez

Hannes du Preez is a self-taught developer who started learning to program in the days of QBasic. He has written several articles over the years detailing his programming quests and adventures. .NET is his second love, just after his wife and kid. He has always been an avid supporter of .NET since the beginning and is an expert in VB and C#. He was given the Microsoft Most Valuable Professional Award for .NET (2008–2017). He has worked as a moderator and an article reviewer on online forums and currently works as a C# developer and writes articles for CodeGuru.com, Developer.com, DevX.com, and the Database journal.
His first book Visual Studio 2019 In Depth is currently on sale on Amazon and Bpb Publications.

You could reach him at: ojdupreez1978[at]gmail[dot]com

Related Articles

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date