溫馨提示×

C# 打印輸出如何連接打印機

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

在C#中連接到打印機并輸出內容,可以使用System.Drawing.Printing命名空間中的PrintDocument類。以下是一個簡單的示例代碼,演示如何連接到打印機并打印輸出:

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

class Program
{
    static void Main()
    {
        PrintDocument pd = new PrintDocument();
        pd.PrintPage += new PrintPageEventHandler(PrintOutput);

        pd.Print();
    }

    static void PrintOutput(object sender, PrintPageEventArgs e)
    {
        Graphics g = e.Graphics;
        Font font = new Font("Arial", 12);

        g.DrawString("Hello, Printer!", font, Brushes.Black, 100, 100);
    }
}

這個示例會連接到默認打印機并在打印時輸出"Hello, Printer!"。你可以根據自己的需求修改PrintOutput方法中的內容,以便打印所需的文本或圖像等信息。

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