如何在c#中添加文本到图标?

ira*_*hil 7 .net c# wpf gdi+ gdi

我想在系统托盘中显示一个图标[.ico文件],并在运行时添加一些文本.是否有任何原生WPF方式可以做到这一点?或GDI +的片段也将不胜感激.

谢谢.

ira*_*hil 5

这是适合我的代码,

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;
}
Run Code Online (Sandbox Code Playgroud)