.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组件一起使用来控制文档 ...
随机推荐
- python学习第一天基础篇
学习背景:决定开始学习python之前,因为公司基本都是微软系统,所以很少碰到linux系统,机缘巧合接到了一个项目是使用shell对mysql进行backup,因为公司唯一的系统工程师是微软在行,对 ...
- hibernate5(9)注解映射[1]多对一单向关联
在博客站点中,我们可能须要从某一篇文章找到其所关联的作者.这就须要从文章方建立起对用户的关联,即是多对一的映射关系. 如今先看一个配置实例:我们的文章实体类 package com.zeng.mode ...
- Android ImageLoader(Android-Universal-Image-Loader)【1】概述及使用简单介绍
Android ImageLoader(Android-Universal-Image-Loader)[1]概述及使用简单介绍 一,前言:为什么要引入Android-Universal-Imag ...
- 一个简单的双向链表(C++实现)
直接上代码,亲测有用. #ifndef __DLINK_H__ #define __DLINK_H__ /* [phead] -> [index0] -> [index1] -> [ ...
- CNN中的卷积操作的参数数计算
之前一直以为卷积是二维的操作,而到今天才发现卷积其实是在volume上的卷积.比如输入的数据是channels*height*width(3*10*10),我们定义一个核函数大小为3*3,则输出是8* ...
- gunicorn 信号处理(SIGHUP,SIGUSR2)
在这篇文章中,提到了Master进程对信号的处理函数,其中有两个信号比较有意思. SIGHUP:用来热更新(Reload)应用 SIGUSR2:用来在线升级(upgrade on the fly)gu ...
- idea svn 设置忽略 文件
这里的忽略一直灰色的,可以进入 这里的版本控制里进行忽略选择 或者 这里进行添加 这里有三个选择 按照顺序 1.忽略指定的文件 2.忽略文件夹下所有文件 3.忽略符合匹配规则的文件 到Commit C ...
- 【功能代码】---3 JS判断字符串是否包含某个字符串
JS判断字符串是否包含某个字符串 var str ="abc"; if(str.indexOf("bc")>-1){ alert('str中包含bc字符串 ...
- iOS学习之Socket使用简明教程- AsyncSocket
转载自:http://my.oschina.net/joanfen/blog/287238 如果需要在项目中像QQ微信一样做到即时通讯,必须使用socket通讯,本人也是刚学习,分享一下,有什么不对的 ...
- Python下载一张图片与有道词典
1.下载一张图片代码1 import urllib.request response = urllib.request.urlopen('http://photocdn.sohu.com/201009 ...