using System; using System.Drawing; using System.IO; using System.Reflection; using System.Windows.Forms; namespace TfsExcelImporter { /// /// 应用图标。exe 的 Win32 图标资源由 csproj 的 ApplicationIcon 提供, /// 这里负责窗口标题栏/任务栏用的 Form.Icon:从内嵌的 app.ico(9 个尺寸帧) /// 直接构造,系统按 DPI 取 16/32/48;取不到再退回提取 exe 自身图标。 /// internal static class AppIcon { private static Icon _cached; private static bool _tried; public static Icon Load() { if (_tried) return _cached; _tried = true; try { using (Stream s = Assembly.GetExecutingAssembly() .GetManifestResourceStream("app.ico")) { if (s != null) _cached = new Icon(s); } } catch { // 内嵌 ICO 解析失败(例如只认 BMP 帧的极端情况):忽略,走下面的兜底 _cached = null; } if (_cached == null) { try { _cached = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { } } return _cached; } } }