[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Make a Windows Forms application display icons at appropriate sizes in C#

[Make a Windows Forms application display icons at appropriate sizes in C#]

Setting a form's icon is easy. Simply select the form in the Form Editor and set its Icon property.

Windows uses this icon in many different ways. For example, it displays a small icon in the form's upper left corner and on the taskbar. When you press Alt-Tab, it displays a larger icon in the Task Manager. Windows Explorer also displays an icon for the executable program.

To get the best result in all cases, the icon file should contain several different icon formats. For example, give it a 32×32 pixel image for use by Task Manager and a 16×16 pixel version for use by the form's corner and the taskbar. Now the system can pick the most appropriate version when it needs it.

To make Windows Explorer show an icon for the executable image, open the Project menu and select Properties. On the Application tab, below the "Icon and manifest" option button, select the icon file that you want to use in the Icon box.

Note that the results aren't always perfect. If Windows wants a size that it can't find, it resizes an existing image to fit. Unfortunately the sizes you need also depend on the version of Windows you are using. At a bare minimum you should have the 16×16 and 32×32. The 48×48 pixel size also seems to be useful sometimes, and some versions of Windows will resize a 256×256 version if they need other sizes.

Windows Store and Windows Phone apps also use 150×150, 310×150, 30×30, 620×300, 50×50 sizes and more.

To be complete you should include as many of those sizes as possible.

Also note that for best results you should not simply resize the same image for every other size. For example, large images that's reduced to a small size often loses resolution so you can't read text or see symbols properly. Similarly a small image that's enlarged often becomes a fuzzy blob. For the best results, you may start with a resized image but then you may need to modify it.

Note that some tools can also produce high-quality images at different sizes, similar to the way a WPF program can produce high-quality results at any scale. Those tools may allow you to use the same underlying designer file to produce images at many sizes, although you may still need to do some tweaking.

In my next post, I'll provide more information about setting application icons for Windows Store and Windows Phone apps.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.