How to control the orientation of Drawstring?

隐身守侯 提交于 2019-12-24 16:54:30

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5369869/how-to-control-the-orientation-of-drawstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!