Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using embedded resource icon as app icon in C#

I'm trying to figure a way to specify my C# application to use an embedded resource (icon) as my application icon (the one displayed for taskbar, task switch, etc). Yet, as I already embedded my icon in a resource, I can manage to use it in my forms but not with my application yet.

In fact, if someone could first tell me where I'll be able to set this (which file) by hand instead of using the VS2010 GUI to specify it, that'd be a great start!

Yet, my icon is available in these 2 ways : {{Namespace}}.Properties.Resources.c_name.ico and in {{Namespace}}.Refs.c_name.ico (as a property of a public static class inside a class library).

like image 684
MensSana Avatar asked Jan 22 '26 10:01

MensSana


2 Answers

Windows is an unmanaged operating system that doesn't know beans about managed resources. The only icon it can display is one that's embedded as an unmanaged resource. You can see what unmanaged resources look like in Visual Studio. Use File + Open + File and pick a .NET exe file (won't work in Express). A .NET program should have three of them, an icon, a manifest that declares the program compatible with UAC and a Version resource. This is all done automatically by the compiler, note for example how the Version resource properties match the attributes you set in AssemblyInfo.cs

The IDE makes it simple to set the icon for a program, you use Project + Properties, Application tab, Icon setting. Just pick the same .ico file as you embedded as a managed resource. Forget about trying to share, it cannot work by design.

like image 130
Hans Passant Avatar answered Jan 24 '26 23:01

Hans Passant


Simply set Icon=yourNamespace.Properties.Resources.yourEmbeddedIconName;

like image 20
Andrija Avatar answered Jan 24 '26 23:01

Andrija



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!