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



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual C# 2005, Express Edition
  • Microsoft Visual C# .NET (2003)

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. 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.
  2. From the toolbox, drag an ImageList control onto Form1.

    ImageList1 is created on Form1.
  3. Right-click ImageList1, and then click Properties.
  4. In the Properties window, click the Images properties ellipsis button (...), and then click Add.
  5. 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.
  6. From the toolbox, drag the ImageList control to Form1.

    ImageList2 is created on Form1.
  7. From the toolbox, drag a Button control onto Form1.
  8. 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("count of images in ImageList1 is:" & ImageList1.Images.Count)
    MsgBox("count of images in ImageList2 is:" & ImageList2.Images.Count)
    Visual C# .NET or Visual C# 2005
    imageList2.ImageStream=imageList1.ImageStream;
    MessageBox.Show("count of images in ImageList1 is:" + imageList1.Images.Count.ToString());
    MessageBox.Show("count of images in ImageList2 is:" + imageList2.Images.Count.ToString()); 
  9. On the Debug menu, click Start.
  10. Click Button1. Verify that there are no images in ImageList2.

REFERENCES

For more information, see your .NET Framework Software Development Kit documentation or visit the following MSDN Web site :

ImageList Class
http://www.msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsImageListClassTopic.asp

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005applies kbvs2005swept kbWindowsForms kbCtrl kbImgList kbControl kbBug KB814349 kbAudDeveloper