我想在.Net中获取可执行文件的应用程序图标。我该怎么做?我认为我需要查询它的资源,但我对任何通用解决方案都持开放态度。
从硬路径的角度:
Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(filePath);
从资源 DLL 中:
// Process handle
IntPtr processHandle = System.Diagnostics.Process.GetCurrentProcess().Handle;
// DLL path
string DLLPath = Path.Combine(Environment.SystemDirectory, "shell32.dll");
// Open folder icon index
int iconIndex = 4;
// Extract icon
System.IntPtr oPtr = ExtractIcon(processHandle, DLLPath, iconIndex);
Icon oIcon = Icon.FromHandle(oPtr);
来源:
icon = Icon.ExtractAssociatedIcon(filename);