Fre*_*örk 27
当您调用RotateTransform时,您需要注意坐标系最终的位置.如果运行以下代码,则"倾斜文本"将显示在左边缘的左侧; 所以它不可见:
e.Graphics.Clear(SystemColors.Control);
e.Graphics.DrawString("Normal text", this.Font, SystemBrushes.ControlText, 10, 10);
e.Graphics.RotateTransform(90);
e.Graphics.DrawString("Tilted text", this.Font, SystemBrushes.ControlText, 10, 10);
Run Code Online (Sandbox Code Playgroud)
由于您已将绘图表面倾斜90度(时钟方式),因此y坐标将沿右/左轴(从您的角度)而不是向上/向下移动.左边是更大的数字.因此,要将倾斜文本移动到曲面的可见部分,您需要减小y坐标:
e.Graphics.Clear(SystemColors.Control);
e.Graphics.DrawString("Normal text", this.Font, SystemBrushes.ControlText, 10, 10);
e.Graphics.RotateTransform(90);
e.Graphics.DrawString("Tilted text", this.Font, SystemBrushes.ControlText, 10, -40);
Run Code Online (Sandbox Code Playgroud)
默认情况下,坐标系的原点位于曲面的左上角,因此RotateTransform将围绕该轴旋转曲面.
这是一张图片说明了这一点; 黑色在调用RotateTransform之前,红色在调用RotateTransform(35)之后: