The string is "Hello World " with 10 SPACE chars in the end, but Graphics.DrawString in Right Alignment omits all of SPACE chars, it just draws "Hello World" only.
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rct = new Rectangle(20, 100, 200, 20);
e.Graphics.DrawRectangle(new Pen(Color.Lime), rct);
e.Graphics.DrawString("Hello World ", Font, new SolidBrush(SystemColors.ControlText), rct, new StringFormat() { Alignment = StringAlignment.Far});
base.OnPaint(e);
}

To include the Trailing Spaces when drawing strings with Gdi+
Graphics.DrawStringmethod, pass aStringFormatto a proper overload and add or append (|=) theStringFormatFlags.MeasureTrailingSpacesvalue to theStringFormat.FormatFlagsproperty.Consider using the Gdi
TextRendererclass to draw strings over controls unless you encounter problems like drawing on transparent backgrounds.The previous code could have been written like: