程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

vb打印類

編輯:VB綜合教程
 

以下通用類參考了網絡資料,整合如下功能:

1、直接打印內存數據表DataTable。
附帶函數,將DataGrid、ListView和SQL數據表轉成DataTable;
2、自動分頁功能。根據紙張大小及DataTable行數、打印字體自動計算頁數,列均勻分布,自適應紙張;
3、支持標題、頁頭、頁腳打印。


''=======================================
'DATAGRID控件通用打印類
'中和科技-孫利臣
'於2003年05月27日17:05
'用於打印DATAGRID控件中的數據.
'=======================================


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

Public Class PrintDataTable
'用戶可自定義
Private TableFont As New Font("宋體", 9) '當前要打印文本的字體及字號
Private HeadFont As New Font("黑體", 12, FontStyle.Underline) '表頭字體
Private SubHeadFont As New Font("楷體_GB2312", 10, FontStyle.Regular) '副表頭字體
Private HeadText As String '表頭文字
Private SubHeadLeftText As String '副表頭左文字
Private SubHeadRightText As String '副表頭右文字
Private HeadHeight As Integer = 40 '表頭高度
Private SubHeadHeight As Integer = 30 '副表頭高度
Private FootFont As New Font("黑體", 12, FontStyle.Underline) '表腳字體
Private SubFootFont As New Font("楷體_GB2312", 10, FontStyle.Regular) '副表腳字體
Private FootText As String '表腳文字
Private SubFootLeftText As String '副表腳左文字
Private SubfootRightText As String
Private FootHeight As Integer = 40 '表腳高度
Private SubFootHeight As Integer = 30 '副表腳高度
Dim X_unit As Integer '表的基本單位
Dim Y_unit As Integer = TableFont.Height * 2.5

'以下為模塊內部使用
Private ev As PrintPageEventArgs
Private PrintDocument1 As PrintDocument
Private DataGridColumn As DataColumn
Private DataGridRow As DataRow
Private DataTable1 As DataTable
Private Cols As Integer '當前要打印的列
Private Rows As Integer = 0 '當前要打印的行
Private ColsCount As Integer '當前DATAGRID共有多少列
Private PrintingLineNumber As Integer = 0 '當前正要打印的行號
Private PageRecordNumber As Integer '當前要所要打印的記錄行數,由計算得到.
Private PrintingPageNumber As Integer = 0 '正要打印的頁號
Private PageNumber As Integer '共需要打印的頁數
Private PrintRecordLeave As Integer '當前還有多少頁沒有打印
Private PrintRecordComplete As Integer = 0 '已經打印完的記錄數
Private Pleft As Integer
Private Ptop As Integer
Private Pright As Integer
Private Pbottom As Integer
Private Pwidth As Integer
Private Pheigh As Integer

Private DrawBrush As New SolidBrush(System.Drawing.Color.Black) '當前畫筆顏色
Private PrintRecordNumber As Integer '每頁打印的記錄條數
Private Totalpage As Integer '總共應該打印的頁數

Sub New(ByVal TableSource As DataTable)
DataTable1 = New DataTable
DataTable1 = TableSource
ColsCount = DataTable1.Columns.Count
End Sub

'用戶自定義字體及字號
Public WriteOnly Property SetTableFont() As System.Drawing.Font
Set(ByVal Value As System.Drawing.Font)
TableFont = Value
End Set
End Property
Public WriteOnly Property SetHeadFont() As System.Drawing.Font
Set(ByVal Value As System.Drawing.Font)
HeadFont = Value
End Set
End Property
Public WriteOnly Property SetSubHeadFont() As System.Drawing.Font
Set(ByVal Value As System.Drawing.Font)
SubHeadFont = Value
End Set
End Property
Public WriteOnly Property SetFootFont() As System.Drawing.Font
Set(ByVal Value As System.Drawing.Font)
FootFont = Value
End Set
End Property
Public WriteOnly Property SetSubFootFont() As System.Drawing.Font
Set(ByVal Value As System.Drawing.Font)
SubFootFont = Value
End Set
End Property
Public WriteOnly Property SetHeadText() As String
Set(ByVal Value As String)
HeadText = Value
End Set
End Property
Public WriteOnly Property SetSubHeadLeftText() As String
Set(ByVal Value As String)
SubHeadLeftText = Value
End Set
End Property
Public WriteOnly Property SetSubHeadRightText() As String
Set(ByVal Value As String)
SubHeadRightText = Value
End Set
End Property
Public WriteOnly Property SetFootText() As String
Set(ByVal Value As String)
FootText = Value
End Set
End Property
Public WriteOnly Property SetSubFootLeftText() As String
Set(ByVal Value As String)
SubFootLeftText = Value
End Set
End Property
Public WriteOnly Property SetSubFootRightText() As String
Set(ByVal Value As String)  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved