DataGrid控件通用打印类

时间:2010-03-16 17:38:22  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:nbsp;Imports System.Windows.Forms.DataGrid   Imports System.Drawing.Pen   Imports System.Drawing            ''=======================================   'DATAGRID控件通用打印类   '中和科技-孙利臣   '于2003年05月27日17...
  正文:  Imports System.Drawing.Printing
  Imports System.Drawing.Color
  Imports System.Windows.Forms
  Imports System.Drawing.Font
  Imports System.Drawing.PointF
  Imports System.Windows.Forms.DataGrid
  Imports System.Drawing.Pen
  Imports System.Drawing
  
  
  
  ''=======================================
  'DATAGRID控件通用打印类
  '中和科技-孙利臣
  '于2003年05月27日17:05
  '用于打印DATAGRID控件中的数据.
  
  '=======================================
  
  
  Public Class PrintDataGrid
   '用户可自定义
   Private PrintFont As New Font("宋体", 10) '当前要打印文本的字体及字号
   Private PrintLines As Integer = 50 '当前页共要分成多少行.
   Private PrintRecordNumber As Integer = 45 '当前页共要打印的记录的行数
  
   '以下为模块内部使用
   Private DataGridSource As DataGrid
   Private ev As PrintPageEventArgs
   Private PrintDataGrid As PrintDocument
   Private PrintPriview As PrintPreviewDialog
   Private PageSetup As PageSetupDialog
   Private PrintScale As Double = 1 '当前要打印的数据与DATAGRID控件内数据的比例
  
   Private DataGridColumn As DataColumn
   Private DataGridRow As DataRow
   Private DataGridTable As DataTable
  
   Private Cols As Integer '当前要打印的列
   Private Rows As Integer = 1 '当前要打印的行
  
   Private ColsCount As Integer '当前DATAGRID共有多少列
  
   Private PrintingLineNumber As Integer = 0 '当前正要打印的行号
   Private PageRecordNumber As Integer '当前要所要打印的记录行数,由计算得到.
  
   Dim X_unit As Integer '表的基础单位
   Dim Y_unit As Integer
  
   Private PrintingPageNumber As Integer = 0 '正要打印的页号
  
   Private PageNumber As Integer '共需要打印的页数
   Private PrintRecordLeave As Integer '当前还有多少页没有打印
   Private PrintRecordComplete As Integer = 0 '已经打印完的记录数
  
   Sub New(ByVal TableSource As DataGrid)
   DataGridSource = TableSource
   DataGridTable = New DataTable()
   DataGridTable = DataGridSource.DataSource()
   ColsCount = DataGridTable.Columns.Count
   End Sub
  
   '用户自定义字体及字号
   Public WriteOnly Property setPrintFont() As System.Drawing.Font
   Set(ByVal Value As System.Drawing.Font)
   PrintFont = Value
   End Set
   End Property
  
   '设置每页要打印的的记录条数
   Public WriteOnly Property setPrintRecordNumber() As Integer
   Set(ByVal Value As Integer)
   PrintRecordNumber = Value
   End Set
   End Property
  
  
   Public Sub Print()
   Try
   PrintDataGrid = New System.Drawing.Printing.PrintDocument()
   AddHandler PrintDataGrid.PrintPage, AddressOf Me.PrintDataGrid_PrintPage
   'PrintDataTable.Print()
  
   '打印机设置对话框
   PageSetup = New PageSetupDialog()
   PageSetup.PageSettings = PrintDataGrid.DefaultPageSettings
"DataGrid控件通用打印类"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/aspnet/13252.html

 1/4    1 2 3 4 下一页 尾页


关键字:

关于《DataGrid控件通用打印类》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td