4

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.

Emmanuel F
  • 1,125
  • 1
  • 15
  • 34

3 Answers3

7

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());
David
  • 3,392
  • 3
  • 36
  • 47
1

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.

Vivelin
  • 770
  • 1
  • 10
  • 23
0

Well, I didn't figure out a good way of doing this, but in the end it didn't matter. I ended up using the BalloonTip which allowed me to provide information.

Emmanuel F
  • 1,125
  • 1
  • 15
  • 34