运行效果:

代码:

 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();
}
}
}

完成。

最新文章

  1. ABP(现代ASP.NET样板开发框架)系列之20、ABP展现层——动态生成WebApi
  2. 关于python中的字符串编码理解
  3. mac rvm升级ruby
  4. PHP格式化显示文件大小函数
  5. 《BI那点儿事》双变量的相关分析——相关系数
  6. javascript取得机器名,用户名,读写注册表,启动应用程序
  7. mariadb DML语句及用户授权
  8. web-app1--移动端等比例代码
  9. [转载] java中byte数组与int,long,short间的转换
  10. Python 错误和异常
  11. Servlet的Request.getInputStream()只能读取一次问题
  12. 分针网—每日分享: 怎么轻松学习JavaScript
  13. LVS负载均衡基础介绍及NET、DR模式配置
  14. ERROR! The server quit without updating PID file (/application/mysql-5.6.40/data/db01-51.pid).
  15. Elasticsearch 异常处理
  16. Java中有多个异常, 如何确定捕获顺序(多个catch),先从上到下执行,判断异常的大小,如果包含捕到异常,就进入这个catch,后面的就不再执行
  17. 实现了一下Mp3播放器的功能
  18. Jmeter 抓app包 抓到一半不好用了
  19. php给图片加文字
  20. Linux中find用法

热门文章

  1. 【网络协议】TCP中的四大定时器
  2. BI商业智能项目中的若干风险要素
  3. C# Code Snip
  4. 一些指令 &amp; 一些知识 (Linux Spring log4j...)
  5. springMVC + mybatis 搜索 分页等
  6. Archive for required library: ‘WebContent/WEB-INF/lib/xxx.jar cannot&amp;n
  7. BZOJ 1018
  8. python获取当前路径的方法
  9. MFC中SDI程序创建流程的回顾
  10. 用了好多年的XP换成了Win7