问题
I've assigned an icon to a C# WinForms app using the Project Properties tab. This icon is supplied along with the program manifest at build time. Is there a way to get an System.Drawing.Icon
object of this icon at runtime, without having to embed it in resources again?
I've done my research; There's a way to extract an icon out of an EXE, but nothing I can find to extract the icon off the running C# application from within the application.
回答1:
Did you see the second answer in the link? (How can I get the icon from the executable file only having an instance of it's Process in C#)
//Gets the icon associated with the currently executing assembly
//(or pass a different file path and name for a different executable)
Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
That seems like it's getting the icon for the executing assembly.
来源:https://stackoverflow.com/questions/25403169/get-application-icon-of-c-sharp-winforms-app