Cas*_*ton 3 .net c# windows icons
我正在尝试创建一个非常简单的系统托盘图标,它只是一个带有白色边框的动态彩色圆圈.为此,我们使用Webdings字体.Webdings中的"n"只是一个简单的圆圈.
我目前正在做的几乎就在那里,但是在某些PC上(但不是全部)它最终会在它周围形成一个波涛汹涌的黑色边框:
这是我得到的:
protected static Icon GetTrayIconFromCache(Color statusColor)
{
Bitmap bmp = new Bitmap(16,16);
Graphics circleGraphic = Graphics.FromImage(bmp);
circleGraphic.DrawString("n", new Font("Webdings", 12F, FontStyle.Regular), Brushes.White, -3f, -2f);
circleGraphic.DrawString("n", new Font("Webdings", 9F, FontStyle.Regular), new SolidBrush(statusColor), 0f, -1f);
Icon ico = Icon.FromHandle((bmp).GetHicon());
return ico;
}
Run Code Online (Sandbox Code Playgroud)
无论我尝试什么,我都无法摆脱圆圈外面那些丑陋的黑点.它们没有出现在每个人身上......一些开发人员看不到它,看起来很干净.我们还没有弄清楚那些看起来不错的PC和不合适的PC之间的共性.
但是......有更好的方法吗?
添加TextRenderingHint的AntiAliasGridFit
.
protected static Icon GetTrayIconFromCache(Color statusColor)
{
Bitmap bmp = new Bitmap(16,16);
Graphics circleGraphic = Graphics.FromImage(bmp);
circleGraphic.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
circleGraphic.DrawString("n", new Font("Webdings", 12F, FontStyle.Regular), Brushes.White, -3f, -2f);
circleGraphic.DrawString("n", new Font("Webdings", 9F, FontStyle.Regular), new SolidBrush(statusColor), 0f, -1f);
Icon ico = Icon.FromHandle((bmp).GetHicon());
return ico;
}
Run Code Online (Sandbox Code Playgroud)