How to add text to an icon in C #?

I want to display the [a.ico file] icon in the system tray with the text added to it at runtime. Is there any native WPF way? or a snippet for GDI + would also be grateful.

Thanks.

+6
source share
2 answers

Here is the code that worked for me,

public static Icon GetIcon(string text) { //Create bitmap, kind of canvas Bitmap bitmap = new Bitmap(32, 32); Icon icon = new Icon(@"Images\PomoDomo.ico"); System.Drawing.Font drawFont = new System.Drawing.Font("Calibri", 16, FontStyle.Bold); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap); graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; graphics.DrawIcon(icon, 0, 0); graphics.DrawString(text, drawFont, drawBrush, 1, 2); //To Save icon to disk bitmap.Save("icon.ico", System.Drawing.Imaging.ImageFormat.Icon); Icon createdIcon = Icon.FromHandle(bitmap.GetHicon()); drawFont.Dispose(); drawBrush.Dispose(); graphics.Dispose(); bitmap.Dispose(); return createdIcon; } 
+5
source

Since system tray icons do not have accompanying text, you can either overlay text on the icon itself or use the pop-up tooltip.

Text overlay (perhaps by embedding it in the icon processed by the procedure) would be very inconvenient, but, more importantly, it is probably a bad idea, since the icons are best used to display categorical status information, more detailed information is available in pop- or popup.

For example, if the icon represents the status of incoming messages, then this is enough to show “new mail” or “no new mail” without indicating the number of new messages. This allows you to display a clearer icon, which the user does not have to decrypt in detail.

The grayer area is an icon indicating the status of the process. You might just have “in progress” compared to “full” icons, but I saw icons with progress bars built into them, which I thought was a neat way to do this. Obviously, the progress bar on the small icon does not actually display exact numerical data and may be closer to expressing categorical data (actually not completed, partially completed, completed) depending on the resolution.

If you decide to follow this approach, this link should help:

If you still feel that your use case deserves to be superimposed on the icon, then I think the process of creating the icon will become a way for it. I think you need to add text to the image first and then convert it to an icon. These links will help you with this:

0
source

Source: https://habr.com/ru/post/887780/


All Articles