我需要能夠旋轉標籤中的文本並將其與左側,右側或中心對齊。到目前爲止,我可以在派生標籤的onPaint方法中使用此代碼進行旋轉:在C中對齊旋轉文本#
float width = graphics.MeasureString(Text, this.Font).Width;
float height = graphics.MeasureString(Text, this.Font).Height;
double angle = (_rotationAngle/180) * Math.PI;
graphics.TranslateTransform(
(ClientRectangle.Width + (float)(height * Math.Sin(angle)) - (float)(width * Math.Cos(angle)))/2,
(ClientRectangle.Height - (float)(height * Math.Cos(angle)) - (float)(width * Math.Sin(angle)))/2);
graphics.RotateTransform(270f);
graphics.DrawString(Text, this.Font, textBrush, new PointF(0,0), stringFormat);
graphics.ResetTransform();
而且它工作正常。我可以看到文字旋轉270度。
但是,當我嘗試在stringFormat中設置對齊時,它變得瘋狂,我無法弄清楚發生了什麼。
我怎樣才能讓文字旋轉270度並將其對齊?
你設置什麼定位? – Aliostad 2010-12-16 11:28:58
近乎乍一看,但是當我改變圖形時,我想改變爲遠和中心 – 2010-12-16 11:35:30
,整個「世界」得到改變,所以附近不是很近。你能不能把它放在你想要的位置? – Aliostad 2010-12-16 13:51:44