ラベル内のテキストを回転させ、左、右、または中央に揃える必要があります。これまでのところ、派生ラベルの onPaint メソッドでこのコードを使用して回転を行うことができます。
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 度回転させて上に揃えるにはどうすればよいですか?