运行效果:

代码:

 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. 利用GDataXML解析XML文件

    1.导入GDataXMLNode.h 和 GDataXMLNode.m文件 2.导入libxml2库文件 3.工程target下Bulid Settings  搜索search 找到Hearder S ...

  2. js 乱码解决方案

    如果网页编码规则是utf-8,即在网页头部中可以看到如下代码: 那么js文件中如果有中文字,调用输出时就会出现乱码.解决此个问题的办法如下: 即在引用javascript输出的地方加上charset= ...

  3. CentOS7 安装JDK

    链接地址:http://jingyan.baidu.com/article/c74d60007b85510f6a595dfa.html VMware 10 centos 安装jdk 及mysql 方法 ...

  4. typeof操作符的返回值

    使用typeof操作符 对一个值使用typeof操作符可能返回下列某个字符串: 1):undefined——如果这个值未定义 2):boolean——如果这个值是布尔值 3):string——如果这个 ...

  5. Flask对请求的处理

    由http://www.cnblogs.com/steinliber/p/5133386.html 中可得服务器会把environ和start_response发送给Flask的实例app,返回的是a ...

  6. S2S:分享出的营销机遇

    (速途网专栏 作者:高学争)经常在网上购物的你,有没有遇到过这样的问题:你知道自己想买什么,但是在淘宝上一搜,出来了数以万计的同类型,他们有着同样的价位(甚至可能是同样的图片),但是由不同的商家提供, ...

  7. Hadoop_Lucene

    http://codelife.me/blog/2012/11/03/jackson-polymorphic-deserialization/ http://itindex.net/blog/2012 ...

  8. POJ 2050 Searching the Web

    题意简述:做一个极其简单的搜索系统,对以下四种输入进行分析与搜索: 1. 只有一个单词:如 term, 只需找到含有这个单词的document,然后把这个document的含有这个单词term的那些行 ...

  9. 解决安装oracle后系统变慢问题

    Oracle数据库是一个很占资源的软件,光一个实例服务所占内存,根据其安装时分配的内存就至少要达到256MB以上,再加上其他附属服务,光内存就要占用物理内存的400M左右,虚拟内存也会有等值或更高的损 ...

  10. Ultra-QuickSort(归并排序+离散化树状数组)

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 50517   Accepted: 18534 ...