Where is a .net Application Icon Stored?

喜欢而已 提交于 2019-12-01 06:21:55

问题


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?


回答1:


Try this:

var icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);



回答2:


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.




回答3:


The problem with Icon.ExtractAssociatedIcon is that it only extracts one image from the application's icon. However, applications designed for Win7 or newer typically provide icons with several images in different sizes/resolutions. For getting an icon object with all images included, I found a complete solution here:

http://www.codeproject.com/Articles/29923/Assigning-an-application-s-icon-to-all-forms-in-th



来源:https://stackoverflow.com/questions/3873356/where-is-a-net-application-icon-stored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!