GDI+ DrawString字間距問題,gdidrawstring
/// <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);
}
}
GDI+ Drawstring的字號為4的時,出現文字前面間距大,後面間距小
m_GDIPlusFont = new Font(dc.m_hDC, m_Font);void DrawString(CDCHandle dc, CString strText, CRectHelper rc){Graphics g(dc);SolidBrush solidBrush(Color(255, 255, 255, 255));StringFormat stringFormat;stringFormat.SetAlignment(StringAlignmentNear);stringFormat.SetLineAlignment(StringAlignmentNear);g.DrawString(strText, strText.GetLength(), m_GDIPlusFont, rc, &stringFormat, &solidBrush);}有沒有設置字體格式呀???我一般用GDI+ 畫文字,是這樣用的。
GDI+ drawstring 字體
那台沒有這字體吧,那台機要安裝這個字體文件才行,拖進系統的字體文件夾就會自動安裝,而不是放到程序目錄下