旋转文本进行打印

我正在使用PrintDocument打印页面。 在某一点上,我想将文本旋转90度并打印它,即垂直打印文本。 有任何想法吗 ???

g.RotateTransform(90);

不适用于OnPaint。

当您调用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); 

由于您已将绘图表面倾斜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); 

默认情况下,坐标系的原点位于曲面的左上角,因此RotateTransform将围绕该轴旋转曲面。

这是一张图片说明了这一点; 黑色是在调用RotateTransform之前,红色是在调用RotateTransform(35)之后:

图