[转载]PrintDocument,PrintDialog与PrintPreviewDialog用法总结
一、使用PrintDocument进行打印
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms; namespace PrintTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//实例化打印对象
PrintDocument printDocument1 = new PrintDocument();
//设置打印用的纸张,当设置为Custom的时候,可以自定义纸张的大小
printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", , );
//注册PrintPage事件,打印每一页时会触发该事件
printDocument1.PrintPage += new PrintPageEventHandler(this.PrintDocument_PrintPage);
//开始打印
printDocument1.Print();
}
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//设置打印内容及其字体,颜色和位置
e.Graphics.DrawString("Hello World!", new Font(new FontFamily("黑体"), ), System.Drawing.Brushes.Red, , );
}
}
}
二、使用PrintDialog增加打印对话框
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms; namespace PrintTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//实例化打印对象
PrintDocument printDocument1 = new PrintDocument();
//设置打印用的纸张,当设置为Custom的时候,可以自定义纸张的大小
printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", , );
//注册PrintPage事件,打印每一页时会触发该事件
printDocument1.PrintPage += new PrintPageEventHandler(this.PrintDocument_PrintPage); //初始化打印对话框对象
PrintDialog printDialog1 = new PrintDialog();
//将PrintDialog.UseEXDialog属性设置为True,才可显示出打印对话框
printDialog1.UseEXDialog = true;
//将printDocument1对象赋值给打印对话框的Document属性
printDialog1.Document = printDocument1;
//打开打印对话框
DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
printDocument1.Print();//开始打印
}
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//设置打印内容及其字体,颜色和位置
e.Graphics.DrawString("Hello World!", new Font(new FontFamily("黑体"), ), System.Drawing.Brushes.Red, , );
}
}
}
打印对话框如下图所示:
三、使用PrintPreviewDialog增加打印预览对话框
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms; namespace PrintTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//实例化打印对象
PrintDocument printDocument1 = new PrintDocument();
//设置打印用的纸张,当设置为Custom的时候,可以自定义纸张的大小
printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", , );
//注册PrintPage事件,打印每一页时会触发该事件
printDocument1.PrintPage += new PrintPageEventHandler(this.PrintDocument_PrintPage); //初始化打印预览对话框对象
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
//将printDocument1对象赋值给打印预览对话框的Document属性
printPreviewDialog1.Document = printDocument1;
//打开打印预览对话框
DialogResult result = printPreviewDialog1.ShowDialog();
if (result == DialogResult.OK)
printDocument1.Print();//开始打印
}
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//设置打印内容及其字体,颜色和位置
e.Graphics.DrawString("Hello World!", new Font(new FontFamily("黑体"), ), System.Drawing.Brushes.Red, , );
}
}
}
打印时,会显示下图所示预览画面:
注意:PrintDialog与PrintPreviewDialog位于名称空间System.Windows.Forms(程序集为System.Windows.Forms.dll)中,而PrintDocument位于名称空间System.Drawing.Printing(程序集为System.Drawing.dll)中。
[转载]PrintDocument,PrintDialog与PrintPreviewDialog用法总结的更多相关文章
- [转载]PyTorch中permute的用法
[转载]PyTorch中permute的用法 来源:https://blog.csdn.net/york1996/article/details/81876886 permute(dims) 将ten ...
- 转载:Hadoop排序工具用法小结
本文转载自Silhouette的文章,原文地址:http://www.dreamingfish123.info/?p=1102 Hadoop排序工具用法小结 发表于 2014 年 8 月 25 日 由 ...
- 【转载】python super的用法
转载地址: http://blog.csdn.net/cxm19830125/article/details/20610533 super的用法是调用继承类的初始化方法,如下面的代码: class A ...
- [转载] 跟着实例学习zookeeper 的用法
原文: http://ifeve.com/zookeeper-curato-framework/ zookeeper 的原生客户端库过于底层, 用户为了使用 zookeeper需要编写大量的代码, 为 ...
- 【转载】extern "C"的用法解析(原博主就是抄百度百科的,不如另外一篇好)
[说明]文章转载自Rollen Holt 的文章 http://www.cnblogs.com/rollenholt/archive/2012/03/20/2409046.html --------- ...
- (转载)mysql group by 用法解析(详细)
(转载)http://blog.tianya.cn/blogger/post_read.asp?BlogID=4221189&PostID=47881614 mysql distinct 去重 ...
- (转载)mysql中limit用法
(转载)http://hi.baidu.com/sppeivan/item/e45179375d6778c62f8ec221 mysql中limit用法 使用查询语句的时候,经常要返回前几条或者中 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- [转载]js中return的用法
一.返回控制与函数结果,语法为:return 表达式; 语句结束函数执行,返回调用函数,而且把表达式的值作为函数的结果 二.返回控制,无函数结果,语法为:return; 在大多数情况下,为事件处理函 ...
随机推荐
- Python3实现ICMP远控后门(下)之“Boss”出场
ICMP后门 前言 第一篇:Python3实现ICMP远控后门(上) 第二篇:Python3实现ICMP远控后门(上)_补充篇 第三篇:Python3实现ICMP远控后门(中)之"嗅探&qu ...
- 使用box-shadow进行画图(性能优化终结者)
最近突然想做一些好玩的东西,找来找去,想到了之前曾经在网上看到过有人用box-shadow画了一副蒙娜丽莎出来感觉这个挺有意思,正好趁着周末,自己也搞一波 前言 在线地址: 优化前的版本优化后的版本源 ...
- 读书笔记---HTML5实战 MARCO CASARIO(前六章)
1:行内元素转化为块级元素①display②position③float; 2:语义化; 3:微数据itemscope/itemprop/itemtype; 4:新表单元素,form外的表单元素可以用 ...
- anguments
anguments是一个对象,长得很像数组的对象,但不是数组,而是伪数组. arguments的内容是函数运行时的实参列表 (function(d, e, f) { console.log(argum ...
- 问题(一) DebugAugmenter
问题: DebugAugmenter的作用是什么?是任何一个自创建的变量都可以取代它还是它有特定含义? public class DebugAugmenter Test { @Test public ...
- TestNG详解-深度好文
转自: https://blog.csdn.net/lykangjia/article/details/56485295 TestNG详解-深度好文 2017年02月22日 14:51:52 阅读数: ...
- 【莫比乌斯反演】BZOJ2005 [NOI2010]能量采集
Description 求sigma gcd(x,y)*2-1,1<=x<=n, 1<=y<=m.n, m<=1e5. Solution f(n)为gcd正好是n的(x, ...
- BZOJ_4804_欧拉心算_欧拉函数
BZOJ_4804_欧拉心算_欧拉函数 Description 给出一个数字N Input 第一行为一个正整数T,表示数据组数. 接下来T行为询问,每行包含一个正整数N. T<=5000,N&l ...
- BZOJ_3932_[CQOI2015]任务查询系统_主席树
BZOJ_3932_[CQOI2015]任务查询系统_主席树 题意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,P ...
- enumerate取下标
for index,item in enumerate(product_list): # print(product_list.index(item),item) print(index,item) ...