当前位置:   article > 正文

.NET下支持多框架的托盘功能NotifyIconEx(WPF / WinForms / Avalonia / WinUI / MAUI / Wice)

.NET下支持多框架的托盘功能NotifyIconEx(WPF / WinForms / Avalonia / WinUI / MAUI / Wice)

支持 WPF / WinForms / Avalonia / WinUI / MAUI / Wice 应用。

先看效果:

  1. using NotifyIconEx;
  2. var notifyIcon = new NotifyIcon()
  3. {
  4. Text = "NotifyIcon",
  5. Icon = Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule?.FileName!)!
  6. };
  7. notifyIcon.AddMenu("MenuItem1", new Bitmap(ResourceHelper.GetStream("pack://application:,,,/Assets/Images/Lock.png")));
  8. var toDisableItem = notifyIcon.AddMenu("MenuItem2", new Bitmap(ResourceHelper.GetStream("pack://application:,,,/Assets/Images/Lock.png")));
  9. notifyIcon.AddMenu("-");
  10. notifyIcon.AddMenu("MenuItem3");
  11. notifyIcon.AddMenu("MenuItem4", true);
  12. notifyIcon.AddMenu("MenuItem5", OnClick);
  13. notifyIcon.AddMenu("-");
  14. notifyIcon.AddMenu("SubMenu", null!,
  15. [
  16. new ToolStripMenuItem("SubMenuItem1"),
  17. new ToolStripMenuItem("SubMenuItem2"),
  18. new ToolStripMenuItem("SubMenuItem3"),
  19. new ToolStripMenuItem("SubSubMenu", null!,
  20. [
  21. new ToolStripMenuItem("SubSubMenuItem1"),
  22. new ToolStripMenuItem("SubSubMenuItem2"),
  23. new ToolStripMenuItem("SubSubMenuItem3")
  24. ])
  25. ]);
  26. notifyIcon.AddMenu("-");
  27. notifyIcon.AddMenu("Exit", (_, _) => Current.Shutdown());
  28. notifyIcon.BalloonTipShown += OnBalloonTipShown;
  29. toDisableItem.Enabled = false;
  30. void OnBalloonTipShown(object? sender, EventArgs e)
  31. {
  32. Debug.WriteLine("OnBalloonTipShown");
  33. }
  34. void OnClick(object? sender, EventArgs e)
  35. {
  36. notifyIcon.BalloonTipTitle = "Title";
  37. notifyIcon.BalloonTipText = "This Balloon Tips";
  38. notifyIcon.ShowBalloonTip(5);
  39. }

可用于 .NET 5.0 以及 .NET Framework 4.6.2。

示例工程:

  1. NotifyIcon.Demo.Avalonia for Avalonia Application.

  2. NotifyIcon.Demo.Maui for MAUI Application.

  3. NotifyIcon.Demo.WPF for WPF Application.

  4. NotifyIcon.Demo.Wice for Wice Application.

  5. NotifyIcon.Demo.WinForm for WinForms Application.

  6. NotifyIcon.Demo.WinUI for WinUI Application.

开源链接:https://github.com/lemutec/NotifyIconEx 

Nuget包:NuGet Gallery | NotifyIconEx 1.0.9

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/869630
推荐阅读
相关标签
  

闽ICP备14008679号