[.Net码农]PrintDocument.Print 方法
来源:互联网 发布:怎样自学办公软件 编辑:程序博客网 时间:2024/05/24 01:50
http://msdn.microsoft.com/zh-cn/library/system.drawing.printing.printdocument.print(v=vs.90).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-4
命名空间: System.Drawing.Printing
程序集: System.Drawing(在 System.Drawing.dll 中)
备注
指定打印输出的方法是处理 PrintPage 事件并使用 PrintPageEventArgs 中包含的 Graphics。
使用 PrinterSettings.PrinterName 属性可指定用哪一台打印机来打印文档。
Print 方法在打印文档时不使用打印对话框。若要为用户提供选择打印设置的能力,则使用 PrintDialog。
示例
下面的代码示例将通过命令行指定的文件打印到默认打印机。
此示例要求每一行都适合于页宽。
using System;using System.IO;using System.Drawing;using System.Drawing.Printing;using System.Windows.Forms; public class PrintingExample { private Font printFont; private StreamReader streamToPrint; static string filePath; public PrintingExample() { Printing(); } // The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; String line=null; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ; // Iterate over the file, printing each line. while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null)) { yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } // If more lines exist, print another page. if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; } // Print the file. public void Printing() { try { streamToPrint = new StreamReader (filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); // Print the document. pd.Print(); } finally { streamToPrint.Close() ; } } catch(Exception ex) { MessageBox.Show(ex.Message); } } // This is the main entry point for the application. public static void Main(string[] args) { string sampleName = Environment.GetCommandLineArgs()[0]; if(args.Length != 1) { Console.WriteLine("Usage: " + sampleName +" <file path>"); return; } filePath = args[0]; new PrintingExample(); } }
示例
下面的代码示例将通过命令行指定的文件打印到默认打印机。
0 0
- [.Net码农]PrintDocument.Print 方法
- printDocument print
- reportViewer To printDocument Print (Single_Page)
- PrintDocument
- Print方法
- [VB.NET]PrintDocument如何打印水晶报表喔?
- vb.net 中隐藏Printdocument“正在打印”窗口
- vb.net 教程 11-1 打印组件 4 PrintDocument 1
- vb.net 教程 11-1 打印组件 4 PrintDocument 2
- vb.net 教程 11-1 打印组件 4 PrintDocument 3
- vb.net 教程 11-1 打印组件 4 PrintDocument 4
- WinFom 通过PrintDocument打印 不显示打印进度提示方法
- print调试方法
- 22. Window print() 方法
- silverlight PrintDocument
- C# PrintDocument
- Net::Telnet, open(), print(), getline()
- net.mindview.util.Print.*使用
- 日经春秋 20150106
- supermap7C的版本问题
- UICollectionView笔记-2
- 黑马程序员——第9天——(面向对象)内部类,异常
- 在javaweb编译的时候出现了BASE64Decoder报错,解决的方案很实用
- [.Net码农]PrintDocument.Print 方法
- 【背景建模】codebook
- Windows字符串类型
- 前导图法与箭线图法
- erb自动生成html页面一例
- 四个人晚上过桥
- android系统源码中引用第三方jar包
- 日经社説 20150106 特殊詐欺の封じ込めに全力を
- 最优最短路径,迪杰斯特拉和弗洛伊德