Blackwood

I'm having trouble setting up icons to be displayed in a TreeView. The default size for TreeView icons is 16x16, and I have a set of .ico files that 16x16 (according to their properties as shown in Windows Explorer, verified by opening in Paint).

In the Designer, I add a ImageList to my form, and set it's ImageSize property to 16x16 and ColorDepth to 32Bit. Still in the Designer, I use Choose Images to add icons to the imagelist. Even though the icons are 16x16, and the ImageList is set to 16x16, the Size and PhysicalDimension properties (both of which are readonly) of the images are set to 32x32. When I use these images at runtime as icons in my TreeView, they are distorted, presumably from having been streched to 32x32 and then shrunk to 16x16.

How can I add a 16x16 icon to an ImageList in the designer



Re: Visual Basic Express Edition How to add 16x16 icon to ImageList

Feng Chen - MSFT

Hi Blackwood,

I write a test program like you have described, and I didn't get the error like yours, and I'm wondering how did you know that "they are distorted", could you please clarify

Thanks!






Re: Visual Basic Express Edition How to add 16x16 icon to ImageList

Blackwood

It's hard to describe the distortion. One example is the open folder icon (the 5th icon in Shell32.dll). I extracted it to a .ico file and in the designer, added it to my ImageList (the ImageList's ImageSize property is set to 16x16). When I use the image as an icon for a TreeNode, the left edge of the folder is missing, and the right edge is fuzzy.

Another example is the icon for .xml files. In my system, this is a blue globe enclosed by "<" and ">" with two horizontal lines underneath. When I use the designer to add this to my ImageList, and assign the image to a TreeNode, the two horizontal lines merge to form one thick line.

I have found that if I add these icons to the ImageList at runtime, they look OK as long as I create the icon as 16x16:

Code Snippet

New Icon(myPath &"\openfolder.ico", New Size(16, 16))

before adding it to the ImageList. If I don't set the size:

Code Snippet
New Icon(myPath &"\openfolder.ico")

I see the distorted version.

The problem seems to be that I can't find a way to add the 16x16 version of the icon to the ImageList at design time. I find that even though the ImageSize property of the ImageList is set to 16x16, after I add the icon, the image's PhysicalDimension Property is set to 32x32.





Re: Visual Basic Express Edition How to add 16x16 icon to ImageList

Feng Chen - MSFT

Hi Blackwood,

I write a program, but I didn't come across the problem like yours. And I'd like to know how exactly do you extract that 5th icon The 5th icon of shell32.dll actually has several sizes: 16x16, 32x32, 48x48 and each of them has 4bit, 8bit and 32bit versions. Which version you are talking about

Thanks!






Re: Visual Basic Express Edition How to add 16x16 icon to ImageList

nobugz

I think I can reproduce your problem. When I use MicroAngelo (an icon editor utility) to extract icon #5 from shell32.dll, save it to disk, then add the icon to a 16x16 ImageList, I see a poorly interpolated version of the icon. When I edit the icon and remove all formats except 16x16x256 colors, I get a nice sharp looking version of the icon.

Looks like ImageList isn't smart enough to select the icon that best matches the ImageList's ImageSize and ColorDepth property. It never was a particularly smart control. This doesn't quite match your scenario but the outcome is the same. Seeing a PhysicalDimension of 32x32 hints that something went wrong when you extracted the icon. I see 16x16 on the edited icon but 32x32 on the un-edited icon.





Re: Visual Basic Express Edition How to add 16x16 icon to ImageList

Blackwood

I used a program called GetIcons to extract all the icons from Shell32.dll. It appears that the extracted icon (in the .ico file) contains at least a 16x16 and a 32x32 icon. I assumed that adding the icon at design time to a 16x16 imagelist would cause the 16x16 version of the icon to be selected, but apparently that is not the case.