Archive

Archive for July, 2009

Rotated text in GDI+, C#

The code to rotate a text in GDI+ is pretty simple:

private void Form1_Paint(object sender, PaintEventArgs e)
{
   int x = this.ClientRectangle.Width / 2;
   int y = this.ClientRectangle.Height / 2;

   e.Graphics.TranslateTransform(x, y);
   e.Graphics.RotateTransform(270);
   e.Graphics.DrawString("Hello", new Font("Arial", 14), new SolidBrush(Color.Black), 0, 0);
   e.Graphics.ResetTransform();

   e.Graphics.DrawLine(new Pen(Color.Black), x, 0, x, this.Size.Height);
   e.Graphics.DrawLine(new Pen(Color.Black), 0, y, this.Size.Width, y);
}

Here is a screenshot of what it’s gave:

RotatedText