I to draw a string at an arbitrary angle

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I am using Graphics.DrawString, I can only draw a string either
horizontally or vertically. Is the a way to draw under arbitrary angle -
parallel to some line?

I would appreciate a code sample.

Thanks,

Val
 
Bob said:
The GDI+ FAQ shows you how.
Yes, but I note in the sample output provided that the rotation of the
text appears to be around the upper left corner of the text 'frame'; is
there a convenient manner in which the rotation can occur based on the
centre left of the text 'frame', so that the text drawn at zero (0) and
180 degrees are aaligned?

-ken
 
As with all matrix operations things are best done around the origin.

You can rotate around any point drawing the text at a position that orients
it correctly.

For example...

Matrix mx=new Matrix(1,0,0,1,0,0);

mx.Rotate(45,MatrixOrder.Append);

mx.Translate(this.ClientRectangle.Width/2,
this.ClientRectangle.Height/2,MatrixOrder.Append);

e.Graphics.Transform=mx;

SizeF sz=e.Graphics.MeasureString("Hello
World!!",this.Font,1024,StringFormat.GenericTypographic);

e.Graphics.DrawString("Hello
World!!",this.Font,Brushes.Black,-sz.Width/2,-sz.Height/2,StringFormat.GenericTypographic);

return;


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top