harper
harper

Reputation: 13690

How to control the orientation of Drawstring?

I want to draw a string as an axis label. When I draw the string with following code, I can read it "from the left". The base line of the text is at the left side.

StringFormat format = CustomGraphics.StringFormat(ContentAlignment.MiddleCenter);
format.FormatFlags |= StringFormatFlags.DirectionVertical;
e.Graphics.DrawString(this.yAxis.Title.Text, this.yAxis.Title.Font,
                      textBrush, e.Bounds, format);
format.FormatFlags &= ~StringFormatFlags.DirectionVertical;

I want to draw vertical but turn the orientation by 180 degrees. How can I control this? Is there another method that I should use?

Upvotes: 1

Views: 4726

Answers (2)

Stuart
Stuart

Reputation: 66882

How do I rotate a label in C#? contains a long and powerful paint method, based originally on http://www.codeproject.com/KB/miscctrl/customtext.aspx

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941455

Use Graphics.RotateTransform() to get the string rotated the way you want it. You'll need TranslateTransform() and MeasureText() to get the start-point right.

Upvotes: 3

Related Questions