溫馨提示×

C# 打印輸出怎么設置紙張大小

c#
小樊
590
2024-07-20 06:16:42
欄目: 編程語言

在C#中打印輸出時,可以使用PrintDocument類來設置紙張大小。以下是一個示例代碼,演示如何設置紙張大?。?/p>

using System;
using System.Drawing;
using System.Drawing.Printing;

class Program
{
    static void Main()
    {
        PrintDocument pd = new PrintDocument();
        pd.PrintPage += new PrintPageEventHandler(PrintPage);
        
        // 設置紙張大小
        pd.DefaultPageSettings.PaperSize = new PaperSize("Custom", 300, 400);
        
        // 打印輸出
        pd.Print();
    }

    private static void PrintPage(object sender, PrintPageEventArgs e)
    {
        // 在打印頁面上繪制內容
        Graphics g = e.Graphics;
        g.DrawString("Hello, world!", new Font("Arial", 12), Brushes.Black, new PointF(100, 100));
    }
}

在上面的示例中,我們創建了一個PrintDocument對象,并設置了紙張大小為300x400。然后通過PrintPage事件處理程序來繪制內容,在這里我們簡單地繪制了一段文字。最后調用Print()方法來執行打印輸出。

請注意,具體支持的紙張大小取決于打印機驅動程序和設置,可能會因打印機的硬件和驅動程序而有所不同。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女