PrintDocument组件打印
2024-09-29 04:33:05
运行效果:
代码:
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();
}
}
}
完成。
最新文章
- ABP(现代ASP.NET样板开发框架)系列之20、ABP展现层——动态生成WebApi
- 关于python中的字符串编码理解
- mac rvm升级ruby
- PHP格式化显示文件大小函数
- 《BI那点儿事》双变量的相关分析——相关系数
- javascript取得机器名,用户名,读写注册表,启动应用程序
- mariadb DML语句及用户授权
- web-app1--移动端等比例代码
- [转载] java中byte数组与int,long,short间的转换
- Python 错误和异常
- Servlet的Request.getInputStream()只能读取一次问题
- 分针网—每日分享: 怎么轻松学习JavaScript
- LVS负载均衡基础介绍及NET、DR模式配置
- ERROR! The server quit without updating PID file (/application/mysql-5.6.40/data/db01-51.pid).
- Elasticsearch 异常处理
- Java中有多个异常, 如何确定捕获顺序(多个catch),先从上到下执行,判断异常的大小,如果包含捕到异常,就进入这个catch,后面的就不再执行
- 实现了一下Mp3播放器的功能
- Jmeter 抓app包 抓到一半不好用了
- php给图片加文字
- Linux中find用法
热门文章
- 【网络协议】TCP中的四大定时器
- BI商业智能项目中的若干风险要素
- C# Code Snip
- 一些指令 &; 一些知识 (Linux Spring log4j...)
- springMVC + mybatis 搜索 分页等
- Archive for required library: ‘WebContent/WEB-INF/lib/xxx.jar cannot&;n
- BZOJ 1018
- python获取当前路径的方法
- MFC中SDI程序创建流程的回顾
- 用了好多年的XP换成了Win7