开发者

How to control the orientation of Drawstring?

开发者 https://www.devze.com 2023-02-18 10:00 出处:网络
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.

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号