C# PrintDocument类
来源:互联网 发布:linux 文件夹写权限 编辑:程序博客网 时间:2024/06/15 22:38
一、 PrintDocument类。
打印类PrintDocument类是包含在System.Drawing.Printing名词空间下的,这个类是用来与打印机进行交流传输使用的,它有专门的属性用来指定应该选择哪个打印机来打印,还有属性设置当前打印的纸张默认设置。
使用方式:PrintDocument pdt = new PrintDocument();
二、 PrintDocument类属性。
例:PrintDocument pdt = new PrintDocument();
pdt.PrinterSettings = new PrinterSettings();
pdt.DefaultPageSettings = new PageSettings();
三、 PrintDocument类事件。
事件方法委托说明PrintPageOnPrintPage
四、 PageSettings类。
这个类是专门用来设置单页打印信息的,这个信息还得获取一下pdt.DefaultPageSettings这个属性。
例:PageSettings ps = pdt.DefaultPageSettings;
当我们获取完这个之后就可以使用Print()方法进行打印了。
例:
using System;using System.Drawing;using System.Windows.Forms;using System.Drawing.Printing;namespace Hty{ class MyForm : Form { PrintDocument pdt; static void Main() {
Application.Run(new MyForm()); } public MyForm() { this.Text = "打印"; Button bt = new Button(); bt.Parent = this; bt.Location = new Point(ClientSize.Width/2-bt.Width/2,ClientSize.Height/2-bt.Height/2); bt.Text = "打印"; bt.Click += new EventHandler(bt_Click); } void bt_Click(object sender, EventArgs e) { pdt = new PrintDocument(); pdt.PrinterSettings = new PrinterSettings(); pdt.DefaultPageSettings = new PageSettings(); PageSettings page = pdt.DefaultPageSettings; pdt.PrintPage += new PrintPageEventHandler(pdt_PrintPage); pdt.Print(); } void pdt_PrintPage(object sender, PrintPageEventArgs e) { Graphics grfx = e.Graphics; grfx.DrawString("aa", new Font("宋体", 20), Brushes.Black, 0, 0); } }}通过以上的例子我们发现,当我们使用打印的时候跟我们以往在其他的软件中使用的打印有很大的区别,区别在于他们都有可选择界面而我们没有这样的界面支持,其实我们也可以做到的微软已经为我们准备好了几个现成的类了,叫做打印对话框类。
五、 PrintPreviewDialog类。
这个类是微软专门制作的打印预览对话框类,如果要想使用这个类就要使用这个类下的Document属性与我们的pdt对象相关联才可以。
例:PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pdt;
ppd.ShowDialog();
注意:当我们使用了这个类时,我们就不能在使用pdt下的Print打印执行方法了。
例:
using System;using System.Drawing;using System.Windows.Forms;using System.Drawing.Printing;namespace Hty{ class MyForm : Form { PrintDocument pdt; static void Main() { Application.Run(new MyForm()); } public MyForm() { this.Text = "打印"; Button bt = new Button(); bt.Parent = this; bt.Location = new Point(ClientSize.Width/2-bt.Width/2,ClientSize.Height/2-bt.Height/2); bt.Text = "打印"; bt.Click += new EventHandler(bt_Click); } void bt_Click(object sender, EventArgs e) { pdt = new PrintDocument(); pdt.PrinterSettings = new PrinterSettings(); pdt.DefaultPageSettings = new PageSettings(); PageSettings page = pdt.DefaultPageSettings; pdt.PrintPage += new PrintPageEventHandler(pdt_PrintPage); //pdt.Print(); PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = pdt; ppd.ShowDialog(); } void pdt_PrintPage(object sender, PrintPageEventArgs e) { Graphics grfx = e.Graphics; grfx.DrawString("aa", new Font("宋体", 20), Brushes.Black, 0, 0); } }}
- C# PrintDocument类
- C# PrintDocument类
- C# PrintDocument
- C# PrintDocument打印
- C# 打印 printDocument
- C# PrintDocument 打印
- C# PrintDocument 打印表格
- PrintDocument
- 在C#中实现打印功能(C#中PrintDialog,PrintDocument的使用)实用的类
- C#中使用[GDI+]+PrintDocument实现打印
- C#使用PrintDocument打印 多页 打印预览
- C#打印(PrintDocument、PrintDialog、PageSetupDialog、PrintPreviewDialog)
- C#打印(PrintDocument、PrintDialog、PageSetupDialog、PrintPreviewDialog)
- C#打印(PrintDocument、PrintDialog、PageSetupDialog、PrintPreviewDialog)
- 【转】C# PrintDocument打印 多页 打印预览
- C#学习笔记之PrintDocument打印
- C# PrintDocument 打印 和 打印预览
- C#中使用GDI+与PrintDocument实现打印
- 关于ios键盘遮挡输入框
- VS2010中的各类文件作用[.sln,.suo,.vcxproj,.vcxproj.filters,.vcxproj.user] .
- 关于 linux 中sockaddr_in
- java生成.exe文件
- 杭电水题--排序 关于strtok的一些问题
- C# PrintDocument类
- Android ANR异常及解决方法
- 机器学习实战笔记(二)KNN(K-Nearest Neighbors) k-近邻算法
- 多图详解 iPhone SDK下载安装教程
- ESRI arcgis 10.1.1 ios skd 中通过gps 设备进行地图上的导航功能
- AWR
- 【Oracle】-【索引】先查数据再建索引,还是先建索引再插数据?
- Win7中CHM打不开的解决方法
- 协议森林02 小喇叭开始广播 (以太网与WiFi协议)