C#实现打印机功能

本文档通过C#展示了如何实现打印功能,利用printDocument组件和PrintPage事件处理程序来绘制要打印的内容。在button点击事件中,读取指定路径的txt文件,并设置打印控制器以消除"正在打印"的提示窗体。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.窗体添加一个button

2.代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Diagnostics;
using System.IO;

namespace printForm
{
    public partial class Form1 : Form
    {
        private string stringToPrint;
        public Form1()
        {
            InitializeComponent();
            this.printDocument1.PrintPage += new PrintPageEventHandler(this.myPrinter_PrintPage);
        }

        private void myPrinter_PrintPage(object sender, PrintPageEventArgs e)
        {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值