I am trying to display 2-3 updatable characters in the system tray rather than display an .ico file - similar to what CoreTemp does when they display the temperature in the system try:
I am using a NotifyIcon in my WinForms application along with the following code:
Font fontToUse = new Font("Microsoft Sans Serif", 8, FontStyle.Regular, GraphicsUnit.Pixel);
Brush brushToUse = new SolidBrush(Color.White);
Bitmap bitmapText = new Bitmap(16, 16);
Graphics g = Drawing.Graphics.FromImage(bitmapText);
IntPtr hIcon;
public void CreateTextIcon(string str)
{
g.Clear(Color.Transparent);
g.DrawString(str, fontToUse, brushToUse, -2, 5);
hIcon = (bitmapText.GetHicon);
NotifyIcon1.Icon = Drawing.Icon.FromHandle(hIcon);
DestroyIcon(hIcon.ToInt32);
}
Sadly this produces a poor result nothing like what CoreTemp gets:
You'd think the solution would be to increase the font size, but anything over size 8 doesn't fit inside the image. Increasing the bitmap from 16x16 to 32x32 does nothing either - it gets resized down.
Then there's the problem of me wanting to display "8.55" instead of just "55" - there's enough space around the icon but it appears unusable.
Is there a better way to do this? Why can windows do the following but I cannot?
Update:
Thanks for @NineBerry for a good solution. To add, I find Tahoma
to be the best font to use.