我想在系统托盘中显示一个图标[.ico 文件],并在运行时添加一些文本。
有没有原生的 WPF 方法可以做到这一点?或 GDI+ 的片段也将不胜感激。
谢谢。
这是对我有用的代码,
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)