2009-06-05 55 views
9

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

g.RotateTransform(90);

不适用于OnPaint。

+0

你是什么意思“不适合的OnPaint工作”? – Lucero 2009-06-05 11:29:31

+0

你是一个救世主!谢谢!!! 只是为了说清楚,你可以绘制任何你喜欢的东西而不旋转,然后你输入: e.Graphics.RotateTransform(90); 以及之后的所有绘制旋转。 – 2012-07-05 13:16:04

回答

26

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

默认坐标系统有其表面的左上角ORIGO,所以这是RotateTransform旋转表面的轴。

这是一个图像,说明这一点;黑色是调用RotateTransform之前,红色是调用RotateTransform(35)之后:

Diagram