简体   繁体   中英

Get application icon of C# WinForms App

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.

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.

Here you can get the icon of the Form itself in case it's what you lookin for:

Bitmap temp = this.Icon.ToBitmap();
temp.Save("c:\\Users\\userName\\Downloads\\icon.png");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM