运行效果:

代码:

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace Print
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private int intCurrentRowIndex = ; public void InitPrintDocument(PrintDocument printDocument)
{
printDocument.DocumentName = "PrintDocument事例!"; foreach (PaperSize ps in printDocument.PrinterSettings.PaperSizes)
{
if (ps.PaperName == "A4")
{
printDocument.DefaultPageSettings.PaperSize = ps;
break;
}
} printDocument.BeginPrint += printDocument_BeginPrint; printDocument.EndPrint += printDocument_EndPrint; printDocument.PrintPage += printDocument_PrintPage;
} void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
int x = ;
int y = ; for (int i = intCurrentRowIndex; i < this.textBox1.Lines.Length; i++)
{
e.Graphics.DrawString(this.textBox1.Lines[i], this.textBox1.Font, Brushes.Black, x, y);
intCurrentRowIndex++; y = this.textBox1.Font.Height + ; if (y > e.PageBounds.Height)
{
e.HasMorePages = true;
break;
}
}
} void printDocument_EndPrint(object sender, PrintEventArgs e)
{
this.label2.Text = "打印完成!";
} void printDocument_BeginPrint(object sender, PrintEventArgs e)
{
intCurrentRowIndex = ;
this.label2.Text = "开始打印!";
Application.DoEvents();
} private void Form1_Load(object sender, EventArgs e)
{
InitPrintDocument(this.printDocument1);
} private void btn_Print_Click(object sender, EventArgs e)
{
this.printDocument1.Print();
} private void btn_Cancle_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

完成。

PrintDocument组件打印的更多相关文章

  1. 使用PrintDocument进行打印

    背景: 1.在winform中,需要直接调用打印机,进行打印处理 2.找了很多实现方法是web的处理,然后查了下度娘,发现可以使用自带类PrintDocument进行处理,所以就有了这篇文章 说明: ...

  2. C# 利用PrintDocument定制打印单据

    本文是利用PrintDocument定制打印单据的小例子,仅供学习分享使用,如果不足之处,还请指正. 涉及知识点: PrintDocument :从 Windows 窗体应用程序打印时,定义一种可重用 ...

  3. 使用PrintDocument定制打印格式

    虽然说使在IE上直接调用打印插件打印已经不常用,但是有时候还是会用到,这里就记录一下. 首先我们列出来我们的打印类 public class PrintService { //打印机名称 privat ...

  4. (转)打印相关_C#(PrintDocument、PrintDialog、PageSetupDialog、PrintPreviewDialog)

    原文地址:http://www.cnblogs.com/smallsoftfox/archive/2012/06/25/2562718.html 参考文章:http://www.cnblogs.com ...

  5. 吉特仓库管理系统-.NET打印问题总结

    在仓储系统的是使用过程中避免不了的是打印单据,仓库系统中包含很多单据:入库单,出库单,盘点单,调拨单,签收单等等,而且还附带着很多的条码标签的打印.本文在此记录一下一个简单的打印问题处理方式.处理问题 ...

  6. 根据第三方库spire.pdf使用指定打印机打印pdf文件

    private void button1_Click(object sender, EventArgs e) { PdfDocument doc = new PdfDocument(); string ...

  7. Windows 打印控件

    Windows窗体的PrintDocument组件用于设置一些属性,这些属性说明,在基于Windows的应用程序中要打印说明内容以及打印文档的能力,可将它与PrintDialog组件一起使用来控制文档 ...

  8. C#教程之打印和打印预览

    最近研究一了一下关于PDF打印和打印预览的功能,在此小小的总结记录一下学习过程. 实现打印和打印预览的方法,一般要实现如下的菜单项:打印.打印预览.页面设置. PrintDocument类 Print ...

  9. .net打印控件基本用法

    1.在winform上加如下控件 2.代码和用法如下: using System; using System.Collections.Generic; using System.ComponentMo ...

随机推荐

  1. x0vncserver Fatal server error: no screens found

    I make a connection through SSH and  then I type: # x0vncserver --PasswordFile=/home/hello/.vnc/pass ...

  2. C#中泛型、程序集一些基本运用(Fifteenth Day)

    今天主要在学习了泛型和程序集以及一些细碎的知识的运用.下面我就把今天所学的总结一下. 理论: 泛型: * 英文名字是Generic,可以让多个类型共享一组代码,泛型允许我们声明类型参数化,可以用不同的 ...

  3. javascripts小结

    1 NAN-isNaN():判断是否数值 2 数值转换 Number()-任何数据类型,parseInt(),parseFloat()-字符串 3数组转字符串 var a=["red&quo ...

  4. linux cmd: netstat

    每天一个linux命令:netstat  http://www.cnblogs.com/peida/archive/2013/03/08/2949194.html netstat命令用于显示与IP.T ...

  5. Value Categories

    Value categories Three primary categories primary categories mixed special Each C++ expression (an o ...

  6. NotePad++ 配置C/C++编译环境

    如果只是测试小程序可以用这种方法 比较方便,如果对于大程序建议使用专业的IDE. 经常需要写一些小程序来运行,又不想运行Visual Studio.Eclipse这样的环境,而Notepad++是一个 ...

  7. oracle修改数据库语言

    alter session set nls_language = 'simplified chinese'; alter session set nls_language = 'american'; ...

  8. JQuery标签去重与数组去重

    如图所示: 代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head ...

  9. perl post 带上请求头

    my $url='https://www.zjcap.cn/business/dispatch_post.do?action=submitAdminLogin'; my $res = $ua-> ...

  10. 谷歌三大核心技术(一)The Google File System中文版

    谷歌三大核心技术(一)The Google File System中文版  The Google File System中文版 译者:alex 摘要 我们设计并实现了Google GFS文件系统,一个 ...