C#打印技术(三)
来源:互联网 发布:甲骨文停止java更新 编辑:程序博客网 时间:2024/05/01 09:28
从Windows窗体应用程序打印时,定义一种可重用的可发送到打印机上的对象。
----------名称空间
System.Drawing.Printing
---------语法
public class PrintDocument : Component
-----------属性
------------方法
---------事件
-------说明
通常情况下,创建 PrintDocument 类的一个实例,设置属性,如 DocumentNameand PrinterSettings,并调用 Print 方法开始执行打印进程。处理 PrintPage 事件,在其中指定要打印,使用 PrintPageEventArgs 的 GraphicsGraphics 属性的输出。
---------代码事例
下下面的代码演示了打印指定文件的内容。
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace printDocument{ public partial class Form1 : Form { private StreamReader streamToPrint; private Font font; public Form1() { InitializeComponent(); } #region 打印按钮被单击事件 private void button1_Click(object sender, EventArgs e) { try { ///---判断是否点击了打印按钮 if (DialogResult.OK == printDialog1.ShowDialog()) { streamToPrint = new StreamReader(@"C:\Users\driver\Desktop\WebClientHelper.cs"); font = new Font("Arial", 10); ///---这里选择了打印按钮,那么执行打印 printDocument1.Print(); } } catch (Exception ex) { streamToPrint.Dispose(); MessageBox.Show(ex.Message); } } #endregion 打印按钮被单击事件 #region 打印事件被触发后,执行打印 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { try { ///--- float linePerPage = 0; float yPos = 0; int count = 0; float leftMargin = e.MarginBounds.Left; float topMargin = e.MarginBounds.Top; string lineStr = null; ///----计算行数 linePerPage = e.MarginBounds.Height / font.GetHeight(e.Graphics); ///---打印每一行 while (count < linePerPage && null != (lineStr = streamToPrint.ReadLine())) { yPos = topMargin + (count * font.GetHeight(e.Graphics)); e.Graphics.DrawString(lineStr, font, Brushes.Blue, leftMargin, yPos, new StringFormat()); count++; } ///---若打印的页数不是一页,则打印其他页 if (null != lineStr) { e.HasMorePages = true; } else { e.HasMorePages = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion 打印事件被触发后,执行打印 }}------打印输出结果(打印格式为PDF)
0 0
- C#打印技术(三)
- C#打印技术(一)
- C#打印技术(二)
- 关于C#打印技术
- 关于C#打印技术
- 关于C#打印技术
- 关于C#打印技术
- C#打印EXCEL(三)
- 如何使用C#里面的打印技术
- C#中Enterprise Services(微软应用程序服务器)技术(三)
- C#学习之多线程开发技术(三)
- C#中的三种分支技术
- DataGrid的打印(三)
- 数组(三)--打印数组
- 打印技术
- C#打印EXCEL(二)
- C# 打印
- C#打印
- maven profile介绍
- UVa 10534 Wavio Sequence
- 【深度学习】在Caffe中配置神经网络的每一层结构
- C语言中的数据类型&常量
- Unity3D 虚拟摇杆 Easy Touch
- C#打印技术(三)
- jiebaR中文分词,并做词云(R语言)
- Oracle数据库中的数据库名、全局数据库名、实例名、ORACLE_SID
- jdbc数据库操作工具类--DBUtil
- ALM的使用过程及图解
- HDU 2680 Choose the best route(Dijkstra,建图的方式很巧妙)
- 按字节提取整形数值(按位与运算符“&”、右移位运算符“>>”)
- android TextView自动滚动以及Java中改变显示内容
- csrf攻击及其防范介绍