支持 WPF / WinForms / Avalonia / WinUI / MAUI / Wice 应用。
先看效果:
using NotifyIconEx;var notifyIcon = new NotifyIcon()
{Text = "NotifyIcon",Icon = Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule?.FileName!)!
};
notifyIcon.AddMenu("MenuItem1", new Bitmap(ResourceHelper.GetStream("pack://application:,,,/Assets/Images/Lock.png")));
var toDisableItem = notifyIcon.AddMenu("MenuItem2", new Bitmap(ResourceHelper.GetStream("pack://application:,,,/Assets/Images/Lock.png")));
notifyIcon.AddMenu("-");
notifyIcon.AddMenu("MenuItem3");
notifyIcon.AddMenu("MenuItem4", true);
notifyIcon.AddMenu("MenuItem5", OnClick);
notifyIcon.AddMenu("-");
notifyIcon.AddMenu("SubMenu", null!,
[new ToolStripMenuItem("SubMenuItem1"),new ToolStripMenuItem("SubMenuItem2"),new ToolStripMenuItem("SubMenuItem3"),new ToolStripMenuItem("SubSubMenu", null!,[new ToolStripMenuItem("SubSubMenuItem1"),new ToolStripMenuItem("SubSubMenuItem2"),new ToolStripMenuItem("SubSubMenuItem3")])
]);
notifyIcon.AddMenu("-");
notifyIcon.AddMenu("Exit", (_, _) => Current.Shutdown());
notifyIcon.BalloonTipShown += OnBalloonTipShown;toDisableItem.Enabled = false;void OnBalloonTipShown(object? sender, EventArgs e)
{Debug.WriteLine("OnBalloonTipShown");
}void OnClick(object? sender, EventArgs e)
{notifyIcon.BalloonTipTitle = "Title";notifyIcon.BalloonTipText = "This Balloon Tips";notifyIcon.ShowBalloonTip(5);
}
可用于 .NET 5.0 以及 .NET Framework 4.6.2。
示例工程:
-
NotifyIcon.Demo.Avalonia for Avalonia Application.
-
NotifyIcon.Demo.Maui for MAUI Application.
-
NotifyIcon.Demo.WPF for WPF Application.
-
NotifyIcon.Demo.Wice for Wice Application.
-
NotifyIcon.Demo.WinForm for WinForms Application.
-
NotifyIcon.Demo.WinUI for WinUI Application.
开源链接:https://github.com/lemutec/NotifyIconEx
Nuget包:NuGet Gallery | NotifyIconEx 1.0.9