ImageList


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-505: 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 the ImageList.ImageCollection for 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 Image:SmartTagGlyph.jpg, a small menu appears with the list of tasks that can be achieved through it.

Image:526-104.jpg


The only task that can be done is to choose the images for the ImageList. This is done through the Images Collection Editor.

Image:526-105.jpg


Images can be added or removed through the buttons provided.


Adding images manually

The MSDN page gives 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)
    + @"\Image.gif");
 
  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


Previous_Page_.gif Next_Page_.gif





Personal tools