大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > C#技巧 > GDI+ DrawString字间距问题

GDI+ DrawString字间距问题

关键词:间距GDIDrawString  阅读(2842) 赞(16)

[摘要]本文是对GDI+ DrawString字间距问题的讲解,对学习C#编程技术有所帮助,与大家分享。
/// <summary>
/// 绘制任意间距文字
/// </summary>
/// <param name= "text "> 文本 </param>
/// <param name= "g "> 绘图对象 </param>
/// <param name= "startPoint "> 起始位置 </param>
/// <param name= "font "> 字体 </param>
/// <param name= "brush "> 画刷 </param>
/// <param name= "sepDist "> 间距 </param>
private void DrawStringEx(string text, Graphics g, PointF startPoint, Font font, Brush brush, float sepDist)
{
PointF pf = startPoint;
SizeF charSize;
char[] ch = text.ToCharArray();
foreach (char c in ch)
{
charSize = g.MeasureString(c.ToString(), font);
g.DrawString(c.ToString(), font, brush, pf);
pf.X += (charSize.Width + sepDist);
}
}


相关评论