DataGridView打印类

简介:

【简单用法】:

复制代码
 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.cnblogs.com/zhuqil/archive/2010/03/18/1689225.html,如需转载请自行联系原作者

相关文章
|
10月前
|
C# 数据库
C# DataGridView用法(—)代码绑定数据源
C# DataGridView用法(—)代码绑定数据源
393 1
c#Winform修改datatable的列的操作和一些combox绑定实体类,dataGridview的注意点 弹出确认框 弹出的winform出现的位置 load
ds是DataSet 是Datatable的集合 ds.Tables[0]是得到第一张表 然后就是对dt的操作 将Fill_ID列名修改为 “序号” 依次修改列名 combox绑定list 显示combox上的值是用cmb_name 但是 在窗体加载的时候 cmb_name是 它本身的类型名字 而不是空 只有当它上面绑定有真正的值后才会显示。
1346 0