Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DrawString() - how to rotate ? 2

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
0
0
GB
I'm looking at drawing strings on a panel (along with rectangles and the like).
HOWEVER I want the strings to be vertical rather than horizontal - can this be done easily using DrawString() with some means of rotation ?
Or is there some other way to achieve this ?
Steve
 
don't rotate the text. rotate the matrix of the graphics object you want to apply it to, before you call the drawstring method.

Graphics g = e.Graphics; // your graphics object.
float deg = 45F; // an angle, this one is 45 degrees

g.RotateTransform(deg);
g.DrawString("slopey text is fun");
 
You might also look at StringFormat as this sets a flag
for drawing vertical text.

StringFormat sf = new StringFormat ();

sf.FormatFlags = StringFormatFlags.DirectionVertical;

// Get the context g ... & string str, font, brush, x/y etc

Point center;
center = new Point (x,y);

g.DrawString (str, Font, brush, centre, sf);
 
Thanks for the feedback on this question.
The first suggestion works a treat and have added it into my code succesfully getting the required results.
I'll look at making use of the second way the next time... :)
Thanks again
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top