Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is a .net Application Icon Stored?

I'm trying to figure out where my application's icon is stored in VS 2008. On the startup project's application properties, I added an icon with the setting "Embed manifest with default settings."

I'd like to programatically display the icon in the application, but I can't figure out where the icon is being stored.

How can I get a reference to the application's icon from code?

like image 629
Mashmagar Avatar asked Dec 09 '22 13:12

Mashmagar


2 Answers

Try this:

var icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
like image 112
Andrew Hare Avatar answered Dec 29 '22 18:12

Andrew Hare


It is stored in the unmanaged resource section of an executable. You can see that section with File + Open + File and selecting the DLL or EXE. Open the Icon node. The lowest numbered resource is the one that Windows picks as the application icon.

There's spotty support in the .NET framework for accessing the unmanaged resources of a binary. Your best bet here is to use Icon.ExtractAssociatedIcon() but you cannot control which of the images in the icon you'll get. The pinvoke fallback is LoadImage() but it is difficult to use. By far the best approach is to also make the icon available in your managed resources.

like image 23
Hans Passant Avatar answered Dec 29 '22 17:12

Hans Passant