2
GraphicsPathで文字列を追加するときに、文字間の距離を変更する必要があります。これを行う最善の方法は何ですか?GraphicsPath.AddStringで文字間隔を管理する方法は?
GraphicsPathで文字列を追加するときに、文字間の距離を変更する必要があります。これを行う最善の方法は何ですか?GraphicsPath.AddStringで文字間隔を管理する方法は?
それぞれの文字を個別に描画し、文字間の距離などを調整できます。
public void DrawText(string text, Point at, float distanceBetweenChars, FontFamily fontFamily, float fontSize, Graphics graphics)
{
float currentX = at.X;
for (int i = 0; i < text.Length; i++)
{
using (var path = new GraphicsPath())
{
path.AddString(text.Substring(i, 1), fontFamily, (int)FontStyle.Regular, fontSize,
new Point((int)currentX, at.Y),
StringFormat.GenericDefault);
RectangleF bounds = path.GetBounds();
currentX += bounds.Width + distanceBetweenChars;
graphics.FillPath(new SolidBrush(Color.Black), path);
}
}
}
}