I have an icon that contains 32-bit images of sizes 16x16, 24x24, and 32x32. I create three ImageList objects that contain the three different size images, and assign the ImageList property on my ToolStrip given what size the user selects. However the images displayed on the ToolStrip objects are all scaled versions of the 32x32 image. I can't figure out why when I create the 16x16 ImageList, for example, that it doesn't extract the 16x16 image from the icon. My code essentially looks like this:
ImageList m_imageList16 = new ImageList();
m_imageList16.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
m_imageList16.ImageSize = new System.Drawing.Size(16, 16);
m_imageList16.TransparentColor = System.Drawing.Color.Transparent;
// Open is an icon in my resources that contains various sizes of images.
m_imageList16 .Images.Add(global::MyTestApp.Properties.Resources.Open);
// Later when the user selects the 16 size from a menu, I change the toolbar:
m_toolbar.ImageScalingSize = new Size(16, 16);
m_toolbar.ImageList = m_imageList16;
It seems this just takes the 32x32 size image in my icon and scales it down to 16x16, rather than using the 16x16 image defined in the icon. Can anyone help with this? Thanks in advance for any input!
- Steve
I can't find any evidence to support my theory, but ImageList appears to not be aware of selecting different size icons. My hunch is that it simply converts icons to bitmaps and stores that data.
At MSDN forums, I found this snippet from MVP user nobugz:
Also, this page from CSharpKey seemed a useful resource working with ImageLists and icons. Here's an excerpt:
It seems to be, "reading between the lines" that the ImageList merely stores one size and returns resampled versions of the image stored.
Edit
I found another reference at CodeProject (Embedding Icons in your VB.NET application) that says this: