使用Segoe MDL2 Assets字体作为NotifyIcon的图标。

问题描述 投票:0回答:1

是否可以使用 Segoe MDL2 Assets 字体作为SystemTray应用的图标(NotifyIcon)?

我试过用 本题答案 但没有成功。

but it did not work

c# winforms fonts notifyicon
1个回答
0
投票

你需要通过正确的 统一码点 的字形。

请考虑以下代码段。

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.
© www.soinside.com 2019 - 2024. All rights reserved.