.net打印控件基本用法
1、在winform上加如下控件

2、代码和用法如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace Winform
{
/*
在 Windows 窗体中进行打印主要包括以下两个方面:使用 PrintDocument 组件(Windows 窗体)组件来使用户可以打印;使用 PrintPreviewDialog 控件(Windows 窗体)控件、 PrintDialog 组件(Windows 窗体)组件和 PageSetupDialog 组件(Windows 窗体)组件向了解 Windows 操作系统的用户提供熟悉的图形界面
* printdocument使用方法:1、创建;2、在printpage事件中写每一页的打印逻辑;3、调用print方法
* printPreviewControl用法:1、创建;2、将document属性和printdocument关联;3、在printdocument的printpage事件里写打印逻辑;4、运行程序后会自动调用printpage事件;5、如果要刷新就用InvalidatePreview函数
*/
public partial class UsageOfControl6 : Form
{
string documentContents;//总打印字符
string stringToPrint;///要打印的
public UsageOfControl6()
{
InitializeComponent();
///考虑printPreviewControl组件在初始化时就调用了printdocument的printpage事件,在这里初始化打印数据
using (FileStream stream = new FileStream(@"d:\redist.txt", FileMode.Open))
using (StreamReader reader = new StreamReader(stream))
{
documentContents = reader.ReadToEnd();
}
stringToPrint = documentContents;
} private void UsageOfControl6_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;//打印预览控件
printDialog1.Document = printDocument1;//打印设置控件
pageSetupDialog1.Document=printDocument1;//页面设置控件
printPreviewControl1.Document = printDocument1; using (FileStream stream = new FileStream(@"d:\redist.txt", FileMode.Open))
using (StreamReader reader = new StreamReader(stream))
{
documentContents = reader.ReadToEnd();
}
stringToPrint = documentContents; if (printDialog1.ShowDialog()==DialogResult.OK)///通过printDialog1来设置printdocument1的属性:打印机,打印页数,打印方向
{
pageSetupDialog1.ShowDialog();///打印纸设置,边距,页眉,纸大小,也可以在printDocument1_PrintPage事件中获取e.PageSettings来设置
this.printPreviewDialog1.ShowDialog();///打印预览
printDocument1.Print();
printPreviewControl1.InvalidatePreview();////刷新,会再次调用printdocument的printpage事件
} } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int charactersOnPage = ;
int linesPerPage = ;
// Sets the value of charactersOnPage to the number of characters
// of stringToPrint that will fit within the bounds of the page.
//算出stringToPrint铺满打印页时的打印行数和字符数
e.Graphics.MeasureString(stringToPrint, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage); // Draws the string within the bounds of the page.///打印本页文字
///除了打印文字还可以打印线条,图形,屏幕截图等,可以在批定的位置打
e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic); // Remove the portion of the string that has been printed.
stringToPrint = stringToPrint.Substring(charactersOnPage);//下一页要打的 // Check to see if more pages are to be printed.
e.HasMorePages = (stringToPrint.Length > );///如果没有打印完就打印下一页,会自动调用这个事件来打印下一页 // If there are no more pages, reset the string to be printed.
if (!e.HasMorePages)
stringToPrint = documentContents; } private void button2_Click(object sender, EventArgs e)
{
printPreviewControl1.StartPage += ;///下一页
} private void button3_Click(object sender, EventArgs e)
{
printPreviewControl1.StartPage -= ;///上一页
} private void button4_Click(object sender, EventArgs e)
{
printPreviewControl1.Zoom += 0.1;///放大
} private void button5_Click(object sender, EventArgs e)
{
printPreviewControl1.Zoom -= 0.1;//缩小
}
}
}
.net打印控件基本用法的更多相关文章
- 比较好用的web打印控件——Lodop
前一段时间公司一项目比较特殊,客户要求打印单必须是淘宝上卖的那种三联打印单.如果还是使用原来系统自带的打印的话,就会造成无法打印出来理想的效果,于是找了下相关的打印控件,比较网络上比较流行的几款插件, ...
- Web打印控件Lodop实现表格物流单的打印
Web打印控件Lodop实现表格物流单的打印 一.lodop打印预览效果图 LODOP.PRINT_SETUP();打印维护效果图 LODOP.PREVIEW();打印预览图 二.写在前面 最近项目用 ...
- 基于MVC4+EasyUI的Web开发框架经验总结(16)--使用云打印控件C-Lodop打印页面或套打报关运单信息
在最新的MVC4+EasyUI的Web开发框架里面,我整合了关于网购运单处理的一个模块,其中整合了客户导单.运单合并.到货扫描.扣仓.出仓.查询等各个模块的操作,里面涉及到一些运单套打的操作,不过由于 ...
- winform对话框控件、打印控件
对话框控件: ColorDialog:颜色选择对话框,让用户自行选择一种颜色,使用方法类似FontDialog FontDialog:字体选择对话框,让用户自行选择一种字体(也可以选择字体颜色,需要在 ...
- winform 对话框,保存,另存为,还有打印控件
学习的对话框的种类: 1.打开文件对话框(OpenFileDialog) 2.保存文件对话框(SaveFileDialog) 3.字体对话框(FontDialog) 4.颜色对话框(ColorDial ...
- [2014.01.27]wfPrintOcx 票据打印控件 v5.3
支持选择打印机,并自动记忆选择的打印机. 适合打印各类票据格式. 支持画正方形.长方形.圆形.椭圆.横线.竖线.HTTP图片. 支持数字金额转换成中文大写金额. 可以设置固定宽度的文字自动换行. 组件 ...
- 网页WEB打印控件制作-开放源码
在WEB系统中,打印的确是比较烦人的问题,如果我们能制作一个属于自己的自定义的打印插件,那么我们在后续自定义打印的时候能随心所欲的控制打印,这样的效果对于程序员来说是非常开心的一件事件,本文将自己开发 ...
- lodop打印控件一点记录
今天初步接触了下打印控件 LODOP实现了自动分页,高度宽度都可以自己设定来分页. 页码,使用LODOP.SET_PRINT_STYLE("ItemType", 2); LODOP ...
- Windows 打印控件
Windows窗体的PrintDocument组件用于设置一些属性,这些属性说明,在基于Windows的应用程序中要打印说明内容以及打印文档的能力,可将它与PrintDialog组件一起使用来控制文档 ...
随机推荐
- WebSocket解析
WebSocket解析 转载请注明出处:WebSocket解析 现在,很多网站为了实现推送技术,所用的技术都是轮询.轮询是指在特定的时间间隔(如每一秒),由浏览器对服务器发起HTTP请求,然后由服务器 ...
- 解决EditText跟ScrollView滑动冲突
etContent.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, Motion ...
- ajax初探--实现简单实时验证
学习技术最好的方式就是在做中学,做一个小demo来对前端输入进行实时验证. 利用ajax技术和Sevlet技术来实现,使用原生的js. 源码可访问,我的Github 什么是ajax Ajax 即&qu ...
- [转]压缩感知重构算法之分段正交匹配追踪(StOMP)
分段正交匹配追踪(StagewiseOMP)或者翻译为逐步正交匹配追踪,它是OMP另一种改进算法,每次迭代可以选择多个原子.此算法的输入参数中没有信号稀疏度K,因此相比于ROMP及CoSaMP有独到的 ...
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...
- Idea在导入有maven项目时,不能自动识别pom.xml
当在idea中导入maven项目时,不能自动识别pom文件,显示为普通橙色xml文件. 解决方法:点击最右侧侧边栏,点击添加(蓝的的小加号),选择你导入项目的pom.xml文件
- 前端MVC Vue2学习总结(三)——模板语法、过滤器、计算属性、观察者、Class 与 Style 绑定
Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML 解 ...
- C# 委托与事件详解(三)
今天我接着上面的3篇文章来讲一下,为什么我们在日常的编程活动中遇到这么多sender,EventArgs e 参数:protected void Page_Load(object sender, Ev ...
- 为什么epoll会那么高效
参考(原文简直超赞):https://zhidao.baidu.com/question/687563051895364284.html下面是我结合原文写的,为了便于自己理解:关于阻塞和非阻塞的理解可 ...
- css:background-position > 精灵技术
background-position : length || length background-position : position || position 取值: length : 百分数 ...