How Do I Create a System.Drawing.Icon with Multiple Sizes/Images?

.net, c#, icons, winapi

Solution

An .ico file can have multiple images in it, but when you load an .ico file and create an Icon object, only one of those images is loaded. Windows chooses the most appropriate image based on the current display mode and system settings and uses that one to initialize the `System.Drawing.Icon` object, ignoring the others.

So you can't create a `System.Drawing.Icon` with multiple images, you have to pick one before you create the `Icon` object.

Of course, It is possible to create an Icon at runtime from a bitmap, is that what you are really asking? Or are you asking how to create an .ico file?

Problem

I would like to create a single System.Drawing.Icon programmatically from 32x32, 16x16 Bitmaps. Is this possible? If I load an icon with - ``` Icon myIcon = new Icon(@"C:\myIcon.ico"); ``` ...it can contain multiple images.

Original source