2009-06-05 43 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