Files
WC-CZGKJ/SCADA/Core/IconHelper.cs
2026-05-11 11:09:04 +08:00

41 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 { }
}
}
}