Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to overlay text onto NotifyIcon?

I'm currently writing an application that has a NotifyIcon and I'm trying to figure out a way to overlay text on to it. So for example, if the icon indicates the number of files open, it has the icon plus the number on top of it.

Is there a way to do that? I've seen instances of the NotifyIcon solely being text, SpeedFan for example.

Any suggestions or references would be appreciated.

like image 817
Emmanuel F Avatar asked Mar 01 '23 04:03

Emmanuel F


2 Answers

Add a reference to System.Drawing. The following code is taken from one of my applications, it applies a 2 on the icon.

Graphics canvas;
Bitmap iconBitmap = new Bitmap(16, 16);
canvas = Graphics.FromImage(iconBitmap);

canvas.DrawIcon(YourProject.Resources.YourIcon, 0, 0);

StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;

canvas.DrawString(
    "2",
    new Font("Calibri", 8, FontStyle.Bold),
    new SolidBrush(Color.FromArgb(40, 40, 40)),
    new RectangleF(0, 3, 16, 13),
    format
);

notifyIcon.Icon = Icon.FromHandle(iconBitmap.GetHicon());
like image 59
David Avatar answered Mar 02 '23 17:03

David


My best guess is to generate the icon on the fly. There should be something you can use in System.Drawing. I'm not really familiar with the namespace so I can't give examples. I'm sure others can, though.

like image 34
Vivelin Avatar answered Mar 02 '23 16:03

Vivelin