- Investigating Unsupported Controls in the .NET Compact Framework
- Investigating Unsupported System.Windows.Forms Functionality in the .NET Compact Framework
- Working with the Visual Studio .NET Form Designer
- Understanding the Different Windows Forms Target Platforms
- Working with the Form Control
- Programming the Button Control
- Using the TextBox Control
- Using the Label Control
- Working with RadioButton Controls
- Using the CheckBox Control
- Using the ComboBox Control
- Using the ListBox Control
- Using the NumericUpDown Control
- Using the DomainUpDown Control
- Programming the ProgressBar Control
- Using the StatusBar Control
- Using the TrackBar Control
- Using the ToolBar Control
- Adding Menus with the MainMenu Control
- Using a ContextMenu Control in an Application
- Using the Timer Control
- Using the OpenFileDialog and SaveFileDialog Controls
- Using the Panel Control
- Using the HScrollBar and VScrollBar Controls
- Using the ImageList Control
- Using the PictureBox Control
- Using the ListView Control
- Using the TabControl Control
- Using the TreeView Control
- Working with the DataGrid Control
- In Brief
Using the ImageList Control
The ImageList control is a non-graphical control that is meant to be a container for images. Other .NET Compact Framework controls use the ImageList control to retrieve images they need to display. This is true for the ListView, TreeView, and ToolBar controls. The usage of the ImageList with these controls is discussed in their respective sections.
Images can be added to the control at design time as well as at runtime. To add an ImageControl to a Form, drag an ImageControl from the ToolBox to the application form in the Form Designer. Now click the ellipsis next to the Images property in the Properties window. This will bring up the Image Collection Editor (see Figure 3.17). Use the Image Collection Editor to add the images to the ImageList. It is important to note that the
images will be resized to 16 x 16 pixels by default. You can set the ImageSize property if you want the images to be resized differently. These images also get imported into the resource file for the application. You need not deploy the images along with the application, because they will be embedded inside the application assembly.
Images can also be loaded at runtime. The ImageList control exposes an Images property, which represents the list of images stored in the control. The Images property provides the Add method, which allows you to add images to the list of images. Interestingly, this method will add the image to the head of the list (index 0)not the tail of the list, like other methods that add objects to collections would. The Add method can accept either a System.Drawing.Icon or a System.Drawing.Image. Images loaded at runtime can be either loaded from the file system or loaded from the assembly's resource by using the ResourceManager. The following code demonstrates how to load an image from the assembly's resource file:
C# BitMap image = new BitMap(Assembly.GetExecutingAssembly().GetManifestResourceStream("image1.jpg"); ImageList imgList = new ImageList(); imgList.Images.Add(image); VB Dim imgLst as new ImageList() Dim image as BitMap image = new _ BitMap(Assembly.GetExecutingAssembly().GetManifestResourceStream("image1.jpg") imgList.Images.Add(image)