C# 打印输出如何连接打印机

   2024-10-06 3920
核心提示:在C#中连接到打印机并输出内容,可以使用System.Drawing.Printing命名空间中的PrintDocument类。以下是一个简单的示例代码,演示

在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方法中的内容,以便打印所需的文本或图像等信息。

 
举报打赏
 
更多>同类物流大全
推荐图文
推荐物流大全
点击排行

网站首页  |  关于我们  |  联系方式 | 网站留言    |  赣ICP备2021007278号