Is there a way to get different sizes of the Windows system icons in .NET?

Posted by Andrew Watt on Stack Overflow See other posts from Stack Overflow or by Andrew Watt
Published on 2010-06-13T04:52:57Z Indexed on 2010/06/16 4:52 UTC
Read the original article Hit count: 274

Filed under:
|
|
|

In particular I'd like to be able to get the small (16 x 16) icons at runtime.

I tried this:

new Icon(SystemIcons.Error, SystemInformation.SmallIconSize)

Which supposedly "attempts to find a version of the icon that matches the requested size", but it's still giving me a 32 x 32 icon. I also tried:

Size iconSize = SystemInformation.SmallIconSize;
Bitmap bitmap = new Bitmap(iconSize.Width, iconSize.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
    g.DrawIcon(SystemIcons.Error, new Rectangle(Point.Empty, iconSize));
}

But that just scales the 32 x 32 icon down into an ugly 16 x 16.

I've considered just pulling icons out of the VS Image Library, but I really want them to vary dynamically with the OS (XP icons on XP, Vista icons on Vista, etc.). I'm willing to P/Invoke if that's what it takes.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET