Microsoft KB Archive/834532

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

Article ID: 834532

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Architect

-



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(&quot;ImageList1.ImageStream&quot;), 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:  In the Properties dialog box of the ImageList1 control, click Images, and then click the ellipsis button (…). Add an icon file in the Image Collection Editor dialog box. The icon file must be 32x32. On the View menu, click Designer to switch to design mode, and then expand the Windows Form Designer generated code node.  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 &quot;More Information&quot; section, except replace steps 10 through 12 with the steps that are listed in the &quot;Resolution&quot; section.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the behavior
 Start either Microsoft Visual Studio .NET 2003 or Microsoft Visual Studio .NET 2002.</li> On the File menu, point to New, and then click Project.</li> In the New Project dialog box, click Visual Basic Projects under Project Types, and then click Windows Application under Templates.</li> In the Name box, type Q834532 .</li> 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.</li> Add a Label control to the Form1 form.</li> Add a Button control to the Form1 form.</li> Add an ImageList control to the Form1 form.</li> Right-click ImageList1, and then click Properties.</li> In the Properties dialog box, change the ImageSize property to 32, 32 .</li> Click Images, and then click the ellipsis button (...).</li> Add an icon file in the Image Collection Editor dialog box. The icon file must be 32x32 for the behavior to be reproduced.</li> Double-click Button1 to add the Button1_Click event handler in the code window.</li>  Add the following code in the Button1_Click event handler: Label1.Text = &quot;The ImageList contains &quot; & ImageList1.Images.Count & &quot; Image(s)&quot; </li> Press CTRL+SHIFT+B to build the solution.</li> <li>Press CTRL+F5 to run the project.</li> <li>Click Button1.</li></ol>

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.

<div class="references_section">