Text at any angle
Drawing text at any angle using GDI+ is accomplished using the transformation matrix in the Graphics object.
Figure 1 shows an application that uses the Graphics.RotateTransform method to output text every 36 degrees.

Figure 1.
The code that produced this effect is shown in Listing 1.
Listing 1.
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
string s = "Strings at any angle";
e.Graphics.TranslateTransform(this.ClientSize.Width/2,this.ClientSize.Height/2);
for(int a=0;a<10;a++)
{
e.Graphics.DrawString(s,Font,Brushes.Black,50,0,StringFormat.GenericTypographic);
e.Graphics.RotateTransform(36);
}
}
Note how the origin of the image has been translated to the centre of the screen and the graphics transform progressively rotated by 36 degrees.
Back to the GDI+ FAQ
|