Microsoft KB Archive/814349

= BUG: You cannot load images in the ImageList control by directly assigning the ImageStream property from one ImageList to another =

Article ID: 814349

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition

-



SYMPTOMS
If you try to load images in the ImageList control by directly assigning the ImageStream property from one ImageList to another, the assignment fails.



CAUSE
The ImageStream property obtains the handle to the ImageListStreamer class that is associated with this ImageList. The ImageListStreamer is the data portion of the ImageList. When you perform the assignment, the ImageListStreamer handle is not passed to another instance of an ImageList as detailed in the corresponding documentation. Therefore, images are not loaded.



WORKAROUND
To work around this bug, directly assign the ImageList instance instead of setting the ImageStream property, as in the following code:

Visual Basic .NET or Visual Basic 2005 ImageList2=ImageList1 Visual C# .NET or Visual C# 2005 imageList2=imageList1;



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 In Visual Studio .NET (2003) or Visual Studio 2005, create a new Windows application by using Visual Basic .NET, Visual Basic 2005, Visual C# 2005, or Visual C# .NET.

By default, Form1 is created. From the toolbox, drag an ImageList control onto Form1.

ImageList1 is created on Form1. Right-click ImageList1, and then click Properties. In the Properties window, click the Images properties ellipsis button (...), and then click Add. Locate the Graphics folder in the Visual Studio .NET (2003) directory (for example, C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Graphics), and then add an image file. From the toolbox, drag the ImageList control to Form1.

ImageList2 is created on Form1.</li> From the toolbox, drag a Button control onto Form1.</li>  Double-click Button1, and then add the following code to the Click event procedure:

Visual Basic .NET or Visual Basic 2005 ImageList2.ImageStream = ImageList1.ImageStream MsgBox(&quot;count of images in ImageList1 is:&quot; & ImageList1.Images.Count) MsgBox(&quot;count of images in ImageList2 is:&quot; & ImageList2.Images.Count) Visual C# .NET or Visual C# 2005 imageList2.ImageStream=imageList1.ImageStream; MessageBox.Show(&quot;count of images in ImageList1 is:&quot; + imageList1.Images.Count.ToString); MessageBox.Show(&quot;count of images in ImageList2 is:&quot; + imageList2.Images.Count.ToString); </li> On the Debug menu, click Start.</li> Click Button1. Verify that there are no images in ImageList2.</li></ol>

<div class="references_section">