Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Number to Image for NotifyIcon. gimme some idea to create it.
NotifyIcon will be changed upon condition. Icon will be created automatically by some data.
Creating the icon from number is the problem.
Posted
Updated 5-Mar-11 4:15am
v2

Create a new image of the appropriate size.
Get the Graphics object for the image (using Graphics.FromImage)
Draw the number on the image (using Graphics.DrawString) in the appropriate font and size.
Dispose the graphics object.
Use the image as required.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Mar-11 21:03pm    
Exactacly! :-) My 5.
--SA
Bitmap bmp = new Bitmap(16, 16);
using (Graphics g = Graphics.FromImage(bmp)) // Bmp with clear background of given color
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
string theNumber="8";
g.DrawString(theNumber,drawFont,drawBrush,new Point(100,100))
notifyIcon1.Icon = Icon.FromHandle(bmp.GetHicon());



see also :

Dynamically Generating Icons (safely)[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Mar-11 21:08pm    
Good enough, for illustration, my 4.
In real life those immediate constants should not be hard-coded there (it's more of OP).
Instead of new SolidBrush(Color.Black) better be Brushes.Black.
There is no calls to Dispose (see Griff's Answer).
Dispose should not be called directly but via "using" construct, the ensure calling Dispose on exception.
Did I voted "4" with all that notes? OK, fine... :-)
--SA
AHBB 7-Mar-11 13:27pm    
Thanks yumy

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900