我已使用“项目属性”选项卡为 C# WinForms 应用程序分配了一个图标。该图标在构建时与程序清单一起提供。有没有办法在运行时获取此图标的
System.Drawing.Icon
对象,而不必再次将其嵌入资源中?
我已经完成了我的研究;有一种方法可以从 EXE 中提取图标,但我找不到任何方法可以从应用程序内从正在运行的 C# 应用程序中提取图标。
您看到链接中的第二个答案了吗? (如何从只有 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);
这似乎正在获取正在执行的程序集的图标。
在这里您可以获取表单本身的图标,以防万一它是您想要的:
Bitmap temp = this.Icon.ToBitmap();
temp.Save("c:\\Users\\userName\\Downloads\\icon.png");