快速业务通道

DataGridView打印类

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-20

作者:http://www.codeproject.com/KB/printing/DGVPrinter.aspx

【简单用法】:

1 //
2 // Printing the DataGridView Control
3 // in response to a  toolbar button press
4 //
5 private void printToolStripButton_Click(object  sender, EventArgs e)
6 {
7 DGVPrinter printer = new DGVPrinter();
8  printer.Title = "DataGridView Report";
9 printer.SubTitle = "An Easy to Use  DataGridView Printing Object";
10 printer.SubTitleFormatFlags =  StringFormatFlags.LineLimit |
11 StringFormatFlags.NoClip;
12 printer.PageNumbers  = true;
13 printer.PageNumberInHeader = false;
14 printer.PorportionalColumns =  true;
15 printer.HeaderCellAlignment = StringAlignment.Near;
16 printer.Footer  = "Your Company Name Here";
17 printer.FooterSpacing = 15;
18  printer.PrintDataGridView(datagridviewControl);
19 }

【复杂用法】:

1 //
2 // Printing the DataGridView Control
3 // in response to a  toolbar button press – the myprintsettings and mypagesettings objects are  objects used by the local
4 // program to save printer and page settings
5  //
6 private void printToolStripButton_Click(object sender, EventArgs e)
7  {
8 DGVPrinter printer = new DGVPrinter();
9 printer.Title = "DataGridView  Report";
10 printer.SubTitle = "An Easy to Use DataGridView Printing  Object";
11 printer.SubTitleFormatFlags = StringFormatFlags.LineLimit |
12  StringFormatFlags.NoClip;
13 printer.PageNumbers = true;
14  printer.PageNumberInHeader = false;
15 printer.PorportionalColumns = true;
16  printer.HeaderCellAlignment = StringAlignment.Near;
17 printer.Footer = "Your  Company Name Here";
18 printer.FooterSpacing = 15;
19 // use saved  settings
20 if (null != myprintsettings)
21 printer.PrintDocument.PrinterSettings  = myprintsettings;
22 if (null != mypagesettings)
23  printer.PrintDocument.DefaultPageSettings = mypagesettings;
24 if (DialogResult.OK  == printer.DisplayPrintDialog()) // replace DisplayPrintDialog() with your own print  dialog
25 {
26 // save users'' settings
27 myprintsettings =  printer.PrinterSettings;
28 mypagesettings = printer.PageSettings;
29 // print  without displaying the printdialog
30 printer.PrintNoDisplay (datagridviewControl);
31 }

本文配套源码

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号