0

In my WinForms application, I want to display the notifications count in the app launcher icon.

How can this be achieved ?

Tvd
  • 4,463
  • 18
  • 79
  • 125

1 Answers1

1

I believe this is what you're asking for, unfortunately it is in WPF. Winforms doesn't provide a way to do that. You need to P/Invoke manually.

Download Windows 7 API Code Pack - Shell and use the following.

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, "");
}

You may alter the painting code to achieve the desired effect.

Community
  • 1
  • 1
Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
  • This is what I am looking for exactly. I downloaded code pack & added in my project. Also added using Microsoft.WindowsAPICodePack.Shell; in my cs file, but couldn't access TaskbarManager yet. Am I missing anything ? – Tvd Aug 23 '14 at 08:55
  • umm, You did it manually or used nuget? I used nuget and that worked for me well. You need its dependant package as well. What is the error you get? – Sriram Sakthivel Aug 23 '14 at 08:57
  • I added to my project thru nugget - PM command. App cant recognize TaskbarManager. 'The name TaskbarManager does not exist in current context. – Tvd Aug 23 '14 at 09:01
  • In references, I can see Microsoft.WindowsAPICodePack . I read here - http://www.codeproject.com/Articles/65185/Windows-Taskbar-C-Quick-Reference , so also added PresentationCore, PresentationFramework & windowsBase dll's. But, no success. – Tvd Aug 23 '14 at 09:03
  • I am using .NET 4.5 version. – Tvd Aug 23 '14 at 15:43