This documentation is archived and is not being maintained.

ImageList.ImageCollection Class

Encapsulates the collection of Image objects in an ImageList.


Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public sealed class ImageCollection : IList, 
	ICollection, IEnumerable

The ImageList.ImageCollection type exposes the following members.

Public propertyCountGets the number of images currently in the list.
Public propertyEmptyGets a value indicating whether the ImageList has any images.
Public propertyIsReadOnlyGets a value indicating whether the list is read-only.
Public propertyItem[Int32]Gets or sets an Image at the specified index within the collection.
Public propertyItem[String]Gets an Image with the specified key from the collection.
Public propertyKeysGets the collection of keys associated with the images in the ImageList.ImageCollection.

Public methodAdd(Icon)Adds the specified icon to the ImageList.
Public methodAdd(Image)Adds the specified image to the ImageList.
Public methodAdd(Image, Color)Adds the specified image to the ImageList, using the specified color to generate the mask.
Public methodAdd(String, Icon)Adds an icon with the specified key to the end of the collection.
Public methodAdd(String, Image)Adds an image with the specified key to the end of the collection.
Public methodAddRangeAdds an array of images to the collection.
Public methodAddStripAdds an image strip for the specified image to the ImageList.
Public methodClearRemoves all the images and masks from the ImageList.
Public methodContainsNot supported. The IList.Contains method indicates whether a specified object is contained in the list.
Public methodContainsKeyDetermines if the collection contains an image with the specified key.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorReturns an enumerator that can be used to iterate through the item collection.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfNot supported. The IndexOf method returns the index of a specified object in the list.
Public methodIndexOfKeyDetermines the index of the first occurrence of an image with the specified key in the collection.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveNot supported. The IList.Remove method removes a specified object from the list.
Public methodRemoveAtRemoves an image from the list.
Public methodRemoveByKeyRemoves the image with the specified key from the collection.
Public methodSetKeyNameSets the key for an image in the collection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<TResult>Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)

Explicit interface implemetationPrivate methodICollection.CopyToInfrastructure. Copies the items in this collection to a compatible one-dimensional array, starting at the specified index of the target array.
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedInfrastructure. Gets a value indicating whether access to the collection is synchronized (thread safe).
Explicit interface implemetationPrivate propertyICollection.SyncRootInfrastructure. Gets an object that can be used to synchronize access to the collection.
Explicit interface implemetationPrivate methodIList.AddInfrastructure. Adds the specified image to the ImageList.
Explicit interface implemetationPrivate methodIList.ContainsInfrastructure. Implements the Contains method. Throws a NotSupportedException in all cases.
Explicit interface implemetationPrivate methodIList.IndexOfInfrastructure. Implements the IndexOf method. Throws a NotSupportedException in all cases.
Explicit interface implemetationPrivate methodIList.InsertInfrastructure. Implements the Insert method. Throws a NotSupportedException in all cases.
Explicit interface implemetationPrivate propertyIList.IsFixedSizeInfrastructure. Gets a value indicating whether the ImageList.ImageCollection has a fixed size.
Explicit interface implemetationPrivate propertyIList.ItemInfrastructure. Gets or sets an image in an existing ImageList.ImageCollection.
Explicit interface implemetationPrivate methodIList.RemoveInfrastructure. Implements the Remove. Throws a NotSupportedException in all cases.

This is used to manage the images in the ImageList programmatically, providing methods to add and remove image objects.

The following code example shows how to select, remove, and display images, from the Images property of the ImageList class, which is an ImageList.ImageCollection type.

namespace myImageRotator
	using System;
	using System.Drawing;
	using System.ComponentModel;
	using System.Windows.Forms;

	public class Form1 : System.Windows.Forms.Form
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		protected Graphics myGraphics;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label5;
		private int currentImage = 0;

		public Form1()
			imageList1 = new ImageList () ;

			// The default image size is 16 x 16, which sets up a larger
			// image size. 
			imageList1.ImageSize = new Size(255,255);
			imageList1.TransparentColor = Color.White;

			// Assigns the graphics object to use in the draw options.
			myGraphics = Graphics.FromHwnd(panel1.Handle);

        private void InitializeComponent()
            this.components = new System.ComponentModel.Container();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.label3 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button4 = new System.Windows.Forms.Button();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.panel1 = new System.Windows.Forms.Panel();
            this.label5 = new System.Windows.Forms.Label();

            this.listBox1.Location = new System.Drawing.Point(16, 16);
            this.listBox1.Size = new System.Drawing.Size(400, 95);
            this.listBox1.TabIndex = 0;

            this.label3.Location = new System.Drawing.Point(24, 168);
            this.label3.Text = "label3";

            this.button1.Location = new System.Drawing.Point(96, 128);
            this.button1.Size = new System.Drawing.Size(104, 23);
            this.button1.Text = "Show Next Image";
            this.button1.Click += new System.EventHandler(this.button1_Click);

            this.button2.Location = new System.Drawing.Point(208, 128);
            this.button2.Size = new System.Drawing.Size(104, 23);
            this.button2.Text = "Remove Image";
            this.button2.Click += new System.EventHandler(this.button2_Click);

            this.button3.Location = new System.Drawing.Point(320, 128);
            this.button3.Text = "Clear List";
            this.button3.Click += new System.EventHandler(this.button3_Click);

            this.button4.Location = new System.Drawing.Point(16, 128);
            this.button4.Text = "Open Image";
            this.button4.Click += new System.EventHandler(this.button4_Click);

            this.pictureBox1.Location = new System.Drawing.Point(328, 232);
            this.pictureBox1.Size = new System.Drawing.Size(336, 192);

            this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;

            this.panel1.Location = new System.Drawing.Point(8, 240);
            this.panel1.Size = new System.Drawing.Size(296, 184);

            this.label5.Location = new System.Drawing.Point(168, 168);
            this.label5.Size = new System.Drawing.Size(312, 40);
            this.label5.Text = "label5";

            this.ClientSize = new System.Drawing.Size(672, 461);

        // Display the image.
        private void button1_Click (object sender, System.EventArgs e)
			if(imageList1.Images.Empty != true)
				if(imageList1.Images.Count-1 > currentImage)

                // Draw the image in the panel.

                // Show the image in the PictureBox.
				pictureBox1.Image = imageList1.Images[currentImage];
				label3.Text = "Current image is " + currentImage ;
				listBox1.SelectedIndex = currentImage;
				label5.Text = "Image is " + listBox1.Text ;

        // Remove the image.
		private void button2_Click (object sender, System.EventArgs e)

        // Clear all images.
		private void button3_Click (object sender, System.EventArgs e)

        // Find an image.
		private void button4_Click (object sender, System.EventArgs e)
			openFileDialog1.Multiselect = true ;
			if(openFileDialog1.ShowDialog() == DialogResult.OK)
				if (openFileDialog1.FileNames != null)
					for(int i =0 ; i < openFileDialog1.FileNames.Length ; i++ )


		private void addImage(string imageToLoad)
			if (imageToLoad != "")
        public static void Main(string[] args) 
			Application.Run(new Form1());

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.