【问题标题】:How to control the orientation of Drawstring?如何控制拉绳的方向?
【发布时间】:2011-03-20 16:44:18
【问题描述】:

我想画一个字符串作为轴标签。当我使用以下代码绘制字符串时,我可以“从左侧”读取它。文本的基线位于左侧​​。

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;

我想垂直绘制,但将方向旋转 180 度。我该如何控制呢?我应该使用其他方法吗?

【问题讨论】:

    标签: c# clr gdi+


    【解决方案1】:

    使用 Graphics.RotateTransform() 使字符串按照您想要的方式旋转。你需要 TranslateTransform() 和 MeasureText() 来获得正确的起点。

    【讨论】:

      【解决方案2】:

      How do I rotate a label in C#? 包含一个长而强大的绘制方法,最初基于http://www.codeproject.com/KB/miscctrl/customtext.aspx

      【讨论】:

      • 感谢您提供示例链接。 Hans 提到,这让我对其他方法有了深入的了解。
      猜你喜欢
      • 1970-01-01
      • 2011-12-29
      • 1970-01-01
      • 2011-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多