2

GraphicsPath に文字列を追加するときに、文字間の距離を変更する必要があります。これを行う最善の方法は何ですか?

4

1 に答える 1

0

各キャラクターを個別に描いて、キャラクター間の距離を調整できます。

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);
            }
        }
    }
}
于 2012-08-22T13:41:34.077 に答える