ImageList
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| Exam 70-526 Preparation Guide: Configure the layout and functionality of a Windows Form to display a list of items |
Contents |
An ImageList is used to provide a collection of Image objects for other controls, such as the ListView or TreeView. You can add bitmaps or icons to the ImageList, and the other controls are able to use the images as they require.
Inheritance hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ImageList
Useful properties
-
ColorDepth- Gets the color depth of the image list.
-
-
Images- Gets theImageList.ImageCollectionfor this image list.
-
-
ImageSize- Indicates the size of the images in the image list.
-
-
TransparentColor- Indicates the color to treat as transparent.
-
Images Collection Editor
An ImageList doesn't have a visual presence on a form because it is not a control. Dropping an ImageList onto the designer will put an instance of the component in the component tray. You can then use the Images Collection Editor to add, edit, and remove the images hosted by the component. Changing the images associated with the image list will automatically change the images used by any controls referencing the ImageList.
When you right click on the ImageList and click on the Smart Tag icon
, a small menu appears with the list of tasks that can be achieved through it.
The only task that can be done is to choose the images for the ImageList. This is done through the Images Collection Editor.
Images can be added or removed through the buttons provided.
Adding images manually
The MSDN page give the following example to add an image to the ImageList.ImageCollection using the Add method.
public void addImage() { // Be sure that you use an appropriate escape sequence (such as the // @) when specifying the location of the file. System.Drawing.Image myImage = Image.FromFile(System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + @"\<b>Image.gif</b>"); imageList1.Images.Add(myImage); }
Removing images manually
Images can be removed from the ImageList.ImageCollection using the Remove method.
imageList1.Images.Remove(myImage);
Clearing all images manually
All of the images in an ImageList can be removed from the ImageList.ImageCollection using the Clear method.
imageList1.Images.Clear();
MSDN references
|



