C#將縱向內容打印到橫向紙張上(打印旋轉)

遇到了一個打印問題,設計了一張標籤,要打印的內容是縱向的,要打印在 寬*高=8cm*10cm 的標籤紙上,結果在設計完後發現客戶購買的是 寬*高=10cm*8cm 的標籤紙,於是就嘗試使用 e.PageSettings.Landscape = true 來進行橫向打印,結果發現沒用的,內容還是從上到下打印的,而且最下面被截掉了。

print.DefaultPageSettings.PaperSize = new PaperSize("ERPPaper", 315, 394);
print.PrinterSettings.DefaultPageSettings.Landscape = false;              

 折騰了半天,最終發現用一下兩行代碼可以完美解決問題:

e.Graphics.TranslateTransform(0, 315);  
e.Graphics.RotateTransform(-90.0F);     

整體代碼如下: 

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            #region 80×100
           
            Font font15 = new System.Drawing.Font("黑體", 15F, System.Drawing.FontStyle.Regular);
            Font font18 = new System.Drawing.Font("宋體", 15F, System.Drawing.FontStyle.Regular);

            e.Graphics.TranslateTransform(0, 315);
            e.Graphics.RotateTransform(-90.0F);

            e.Graphics.DrawLine(Pens.Black, 5, 5, 311, 5); 
            e.Graphics.DrawLine(Pens.Black, 5, 5, 5, 390);
            e.Graphics.DrawLine(Pens.Black, 5, 390, 311, 390);
            e.Graphics.DrawLine(Pens.Black, 311, 390, 310 ,5);

            e.Graphics.DrawLine(Pens.Black, 62, 43, 155, 43);
            e.Graphics.DrawLine(Pens.Black, 62, 91, 155, 91);
            e.Graphics.DrawLine(Pens.Black, 62, 139, 288, 139);
            e.Graphics.DrawLine(Pens.Black, 62, 187, 155, 187);
            e.Graphics.DrawLine(Pens.Black, 62, 236, 155, 236);
            e.Graphics.DrawLine(Pens.Black, 75, 283, 155, 283);
            e.Graphics.DrawLine(Pens.Black, 62, 331, 288, 331);
            e.Graphics.DrawLine(Pens.Black, 100, 379, 288, 379);

            e.Graphics.DrawLine(Pens.Black, 211, 43, 300, 43);
            e.Graphics.DrawLine(Pens.Black, 211, 91, 300, 91);
            e.Graphics.DrawLine(Pens.Black, 211, 187, 300, 187);
            e.Graphics.DrawLine(Pens.Black, 211, 236, 300, 236);
            e.Graphics.DrawLine(Pens.Black, 211, 283, 300, 283);

            e.Graphics.DrawString("歸屬:", font15, Brushes.Black, 8, 21);
            e.Graphics.DrawString("品種:", font15, Brushes.Black, 8, 69);
            e.Graphics.DrawString("規格:", font15, Brushes.Black, 8, 113);
            e.Graphics.DrawString("匹數:", font15, Brushes.Black, 8, 161);
            e.Graphics.DrawString("原料:", font15, Brushes.Black, 8, 212);
            e.Graphics.DrawString("明細ID:", font15, Brushes.Black, 8, 259);
            e.Graphics.DrawString("日期:", font15, Brushes.Black, 8, 305);
            e.Graphics.DrawString("堆號區位:", font15, Brushes.Black, 8, 353);

            e.Graphics.DrawString("織廠:", font15, Brushes.Black, 157, 21);
            e.Graphics.DrawString("ID:", font15, Brushes.Black, 157, 69);
            e.Graphics.DrawString("重量:", font15, Brushes.Black, 157, 161);
            e.Graphics.DrawString("批號:", font15, Brushes.Black, 157, 212);
            e.Graphics.DrawString("區位:", font15, Brushes.Black, 157, 259);

            #endregion
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章