【问题标题】:WinForms - Show notification count in app launcher IconWinForms - 在应用启动器图标中显示通知计数
【发布时间】:2014-08-22 11:54:34
【问题描述】:

在我的 WinForms 应用程序中,我想在应用启动器图标中显示通知计数。

如何做到这一点?

【问题讨论】:

  • 什么是 Windows 桌面操作系统中的应用启动器图标?你是在说捷径吗?
  • 不,应用程序运行时底部显示的图标(连同开始按钮)。

标签: winforms count notifications icons app-launcher


【解决方案1】:

我相信this 是您所要求的,不幸的是它在 WPF 中。 Winforms 没有提供这样做的方法。您需要手动 P/Invoke。

下载Windows 7 API Code Pack - Shell 并使用以下内容。

private void SetTaskBarOverlay()
{
    string notificationCount = "3"; //To do: Add this as a parameter

    var bmp = new Bitmap(32, 32);
    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.FillEllipse(Brushes.Blue, new Rectangle(Point.Empty, bmp.Size));
        g.DrawString(notificationCount, new Font("Sans serif", 25, GraphicsUnit.Point),
            Brushes.White, new Rectangle(Point.Empty, bmp.Size));
    }

    var overlay = Icon.FromHandle(bmp.GetHicon());
    TaskbarManager.Instance.SetOverlayIcon(overlay, "");
}

private void RemoveTaskBarOverlay()
{
    TaskbarManager.Instance.SetOverlayIcon(null, "");
}

您可以更改绘画代码以达到所需的效果。

【讨论】:

  • 这正是我正在寻找的。我下载了代码包并添加到我的项目中。还使用 Microsoft.WindowsAPICodePack.Shell 添加;在我的cs文件中,但还不能访问TaskbarManager。我错过了什么吗?
  • 嗯,您是手动完成的还是使用了 nuget?我使用了 nuget,这对我很有效。您还需要它的依赖包。你得到什么错误?
  • 我通过 nugget - PM 命令添加到我的项目中。应用程序无法识别 TaskbarManager。 '名称TaskbarManager在当前上下文中不存在。
  • 在参考资料中,我可以看到 Microsoft.WindowsAPICodePack 。我在这里读到 - codeproject.com/Articles/65185/…,因此还添加了 PresentationCore、PresentationFramework 和 windowsBase dll。但是,没有成功。
  • 我使用的是 .NET 4.5 版本。
猜你喜欢
  • 2013-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-10
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
相关资源
最近更新 更多