41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System;
|
||
using System.Drawing;
|
||
using System.Windows.Forms;
|
||
|
||
namespace MesWork
|
||
{
|
||
/// <summary>
|
||
/// 窗口图标加载工具类(多路径搜索 + exe回退)
|
||
/// </summary>
|
||
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"
|
||
};
|
||
|
||
/// <summary>
|
||
/// 为指定窗体加载图标
|
||
/// </summary>
|
||
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 { }
|
||
}
|
||
}
|
||
}
|