views:

180

answers:

2

I'm developing a WinForms c# 3.0 application. Our designer created quite a lot of .ico files containing all the needed art. The choice of .ico was made because quite often, the same image is needed in several places in different dimensions.

Now, it seems .ico files are really annoying to use in visual studio. The only way to use those images seems to be through images list (which aren't supported by all controls). Compared to other resources, you can't write this :

foo.Image = global::RFQHUB.RFQHUBClient.Properties.Resources.foo; //    Cannot implicitly convert type 'System.Drawing.Icon' to 'System.Drawing.Image'  

Here are the options I'm considering :

  • create ImageLists of all possible sizes referencing all my icons in my main window. Link these ImageLists from other windows and find a way to export Image objects from the ImageList when I can't use it directly ; since ImageList contains a Draw() method, this should probably be possible.
  • convert all the x.ico I've got in several x16.gif ...x48.gif, and use those through resources.

I'd be interested to know if some people have been successfully using .ico resources in a Winform application. In so, how did you set up things ?

+2  A: 

Convert the images into PNG. Point. Whoever decided to use .ico files to start with should get talked to in private - the argument holds no ground.

TomTom
+3  A: 

ICO isn't quite an obsolete format, but it's close. It's still useful for your application icon, but for almost everything else, it's better to use an ImageList for each size that you need. And it's much faster to populate an ImageList from a bitmap that contains multiple images layed out in a grid.

You also want to use an Alpha channel transparency in your bitmaps to get the best result, so storing them as .PNG files in your resources is the best way to go, since PNG supports an alpha channel. ICO and GIF files support only single bit for transparency - every pixel is either fully opaque or fully transparent. An 8 bit alpha channel for transparency looks much nicer.

If you can send your artist back to the drawing board then you should do so, and have him/her do full anti-aliased images with alpha. If you can't, then I suggest that you write a small program to convert all of your icon files into bitmaps suitable for loading into ImageLists.

John Knoeller
IcoFX (http://icofx.ro/) is a freeware which supports batch conversion from .ico to .png. The whole conversion process took me about 10s for hundreds of files
Brann