BUG: You cannot use the ImageList property to add images whose size is 32x32 (834532)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition

SYMPTOMS

If you set the ImageSize property of an ImageList component to 32x32, you cannot later add images that are 32x32 to the ImageList component.

Although you receive no design-time errors, you notice during run time that the ImageList component contains no images.

This behavior occurs only if the ImageSize property is set before you add images. This behavior can only be reproduced with images whose size is 32x32.

CAUSE

If you set the ImageSize property to 32x32 before you add images that are 32x32, the following statement is removed by Microsoft Visual Studio .NET:
Me.ImageList1.ImageStream = _
CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
 
This change causes the image resource not to be loaded at runtime.

Note Although the sample is written in Microsoft Visual Basic .NET, you can reproduce the behavior by using any other programming language in Visual Studio .NET. For example, you can reproduce the behavior by using Microsoft Visual C++ .NET or Microsoft Visual C# .NET.

RESOLUTION

To resolve this problem, you can add the image to the ImageList component, and then modify the ImageSize property of the ImageList component in design mode. To resolve this problem, follow these steps:
  1. In the Properties dialog box of the ImageList1 control, click Images, and then click the ellipsis button (.).
  2. Add an icon file in the Image Collection Editor dialog box. The icon file must be 32x32.
  3. On the View menu, click Designer to switch to design mode, and then expand the Windows Form Designer generated code node.
  4. Locate the following code:
    Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
    Replace the previous code with the following code:
    Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32)

WORKAROUND

To work around this problem, follow the steps to reproduce the behavior in the "More Information" section, except replace steps 10 through 12 with the steps that are listed in the "Resolution" section.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start either Microsoft Visual Studio .NET 2003 or Microsoft Visual Studio .NET 2002.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, click Visual Basic Projects under Project Types, and then click Windows Application under Templates.
  4. In the Name box, type Q834532.
  5. In the Location box, type C:\Test, and then click OK. By default, the Form1.vb form is created and is opened in design mode.
  6. Add a Label control to the Form1 form.
  7. Add a Button control to the Form1 form.
  8. Add an ImageList control to the Form1 form.
  9. Right-click ImageList1, and then click Properties.
  10. In the Properties dialog box, change the ImageSize property to 32, 32.
  11. Click Images, and then click the ellipsis button (...).
  12. Add an icon file in the Image Collection Editor dialog box. The icon file must be 32x32 for the behavior to be reproduced.
  13. Double-click Button1 to add the Button1_Click event handler in the code window.
  14. Add the following code in the Button1_Click event handler:
    Label1.Text = "The ImageList contains " & ImageList1.Images.Count & " Image(s)"
    
  15. Press CTRL+SHIFT+B to build the solution.
  16. Press CTRL+F5 to run the project.
  17. Click Button1.
The results of these steps are as follows:
  • Expected result: The text on the Label1 control changes to The ImageList contains 1.
  • Actual result: The text on the Label1 control changes to The ImageList contains 0.

REFERENCES

For more information about the ImageList class, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:9/14/2005
Keywords:kbvs2002sp1sweep kbIcon kbWindowsForms kbcode kbBug KB834532 kbAudDeveloper