views:

1372

answers:

4

Hi,

I am using c# 2005 i want to write string diagonally on image. But by default c# provides the option to write horizontally or vertically.

how we write diagonally?

Thanks

+4  A: 

Do a Graphics.rotateTransform before the drawString call. Don't forget to reverse the change afterwards, as Phil Wright points out.

moonshadow
You can have lotsa fun adding a semi-random transform for every line in a text editor :)
leppie
+5  A: 

You can use the RotateTransform and TranslateTransform that are available on the Graphics class. Because using DrawString is GDI+ the transforms affects the drawing. So use something like this...

g.RotateTransform(45f);
g.DrawString("My String"...);
g.RotateTransform(-45f);

Don't forget to reverse the change though!

Phil Wright
A: 

There is another way to draw a text vertically which is built in the C#. There is no need of explicit graphics transformation. You can use the StringFormat class. Here is a sample code which draws a text vertically:

StringFormat sf = new StringFormat(); sf.FormatFlags = StringFormatFlags.DirectionVertical; e.Graphics.DrawString("My String", this.Font, Brushes.Black, PointF.Empty, sf);

Chris Hughes
A: 

hello Chris u have right..It can be done in that way..BUT text will be written from top to bottom always and I'm not sure u can change it from bottom to top.. cheers