如何添加文本在C#中的图标? [英] How to add text to icon in c#?
本文介绍了如何添加文本在C#中的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要显示在系统托盘中的图标[一个.ico文件]与一些文本添加到它在运行时。 是否有任何本地WPF办法做到这一点?或片段的GDI +也将不胜感激。
I want to display an icon [a .ico file] in System tray with some text added to it at runtime. Is there any native WPF way to do it? or snippet for GDI+ also would be grateful.
感谢您。
推荐答案
下面是为我工作的code,
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;
}
这篇关于如何添加文本在C#中的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文