运行效果:

代码:

 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. NSDate conversion utilities

    // Gets UTC NSDate from DateTime(.Net/WCF). + (NSDate *)fromDateTime:(NSString *)dateTime { NSDate * ...

  2. Visual Studio warning MSB3270:There was a mismatch between the processor architecture of the project being built "MSIL"

    Problem: There was a mismatch between the processor architecture of the project being built "MS ...

  3. Javascript debugger come accross error

    Problem: “Unable to attach to the process. Another debugger might be attached to the process.” Solut ...

  4. SSIS 连接 PostgreSQL

    因为工作需要,得把psql的表放到SQL Server, 找到一个PGNP(http://www.pgoledb.com/)  的适配器,不过一看要300$就没有去尝试了. 官方倒是有ODBC的驱动. ...

  5. aop切入点表达式

    1.切入点表达式:对指定的方法进行拦截,并且生成代理表达式. 2.拦截所有public方法 <aop:pointcut expression="execution(public * * ...

  6. Servlet乘法表学习笔记

    一.控制台实现乘法表 package com.shanrengo; import java.io.IOException; import java.io.PrintWriter; import jav ...

  7. Linux学习:netstat命令

    Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态等.对于开发来说,很多时候用于查看端口占用情况. 执行netstat命令,其输出结果可以分成两部分: 1)一是“Active ...

  8. 基于visual Studio2013解决C语言竞赛题之0406数列求和

      题目 解决代码及点评 这个题目,还是考察for循环的使用 以及数列规律,该数列的特点是第n个分子 = 第n-1个分子 + 第n-2个分子,分母也是此规律 而另外一个规律是第n个分子和第n- ...

  9. 孙弘与Masa Maso 做互联网最贵的衬衫(2)_人物对话_中国时尚品牌网

    孙弘与Masa Maso 做互联网最贵的衬衫(2)_人物对话_中国时尚品牌网 孙弘与Masa Maso 做互联网最贵的衬衫(2)

  10. Windbg调试命令详解(1)

    转载注明>> [作者:张佩][镜像:http://www.yiiyee.cn/Blog] 1. 概述 用户成功安装微软Windows调试工具集后,能够在安装目录下发现四个调试器程序,分别是 ...