【发布时间】:2020-01-13 08:36:28
【问题描述】:
是否可以使用Segoe MDL2 Assets 字体作为 SystemTray 应用程序的图标 (NotifyIcon)?
我尝试使用an answer from this question,但没有成功:
【问题讨论】:
标签: c# winforms fonts notifyicon
是否可以使用Segoe MDL2 Assets 字体作为 SystemTray 应用程序的图标 (NotifyIcon)?
我尝试使用an answer from this question,但没有成功:
【问题讨论】:
标签: c# winforms fonts notifyicon
您需要传递所需字形的正确Unicode Point。
请考虑以下 sn-p:
using System.Drawing;
using System.Drawing.Text;
//...
public enum Glyphs
{
GlobalNavigationButton = 0xE700,
Wifi = 0xE701,
Bluetooth = 0xE702,
Connect = 0xE703,
InternetSharing = 0xE704,
VPN = 0xE705,
//Add more...
}
//...
public static Icon CreateGlyphIcon(Glyphs glyph)
{
using (var b = new Bitmap(16, 16))
using (Graphics g = Graphics.FromImage(b))
using (var f = new Font("Segoe MDL2 Assets", 12, FontStyle.Regular))
using (var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
{
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
g.DrawString(((char)glyph).ToString(), f, Brushes.White, new Rectangle(0, 0, 16, 16), sf);
return Icon.FromHandle(b.GetHicon());
}
}
用法:
var icon = CreateGlyphIcon(Glyphs.Connect);
//or
var icon = CreateGlyphIcon(Glyphs.Bluetooth);
//...etc.
【讨论】: