C# Drawstring Letter Spacing

beckelmw picture beckelmw · Jun 3, 2010 · Viewed 18.4k times · Source

Is is somehow possible to control letter spacing when using Graphics.DrawString? I cannot find any overload to DrawString or Font that would allow me to do so.

g.DrawString("MyString", 
             new Font("Courier", 44, GraphicsUnit.Pixel), 
             Brushes.Black, 
             new PointF(262, 638));

By letter spacing I mean the distance between letters. With spacing MyString could look like M y S t r i n g if I added enough space.

Answer

Hans Passant picture Hans Passant · Jun 3, 2010

That's not supported out of the box. You'll either have to draw each letter individually (hard to get that right) or insert spaces in the string yourself. You can stretch the letters by using Graphics.ScaleTransform() but that looks fugly.