using System; using System.Drawing; using System.Windows.Forms; namespace MesWork { /// /// 窗口图标加载工具类(多路径搜索 + exe回退) /// public static class IconHelper { private static readonly string[] IconSearchPaths = new[] { System.IO.Path.Combine(Application.StartupPath, "任务管理.ico"), System.IO.Path.Combine(System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location) ?? "", "任务管理.ico"), "任务管理.ico" }; /// /// 为指定窗体加载图标 /// public static void ApplyIcon(Form form) { try { foreach (var path in IconSearchPaths) { if (System.IO.File.Exists(path)) { form.Icon = new Icon(path); return; } } form.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { } } } }