⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_print.bas

📁 print打印功能.实现套打,请下载查看具体的功能介绍.
💻 BAS
字号:
Attribute VB_Name = "Mod_Print"
Option Explicit

Private Type Type_Rect
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private mrect As Type_Rect
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As Type_Rect, ByVal wFormat As Long) As Long

Private Const DT_RIGHT = &H2
Private Const DT_TOP = &H0
Private Const DT_CENTER = &H1
Private Const DT_LEFT = &H0
Private Const DT_NOCLIP = &H100

Public mScreenID As Long, mPrintID As Long, mBillID As Long, mBillView As String

Public mEmptyBill As Boolean

Public mPageWidth As Double, mPageHeight As Double, mLandScape As Boolean
'页边距
Public mPageLeft As Double, mPageRight As Double, mPageUp As Double, mPageDown As Double
Public mPageScale As Double, mFontScale As Double

Public mrowcount As Integer, mRowHeight As Double, mColWidth As Double, mcolcount As Double
Public mOrderBy As String, mGroupBy As String, mBillType As Integer

Public mTotalPage As Integer

Public Sub PreViewBill(msID As Long, PrintID As Long, BillID As Long, Optional nCount As Integer = -1, Optional PreView As Boolean = True, Optional EmptyBill As Boolean = False)

On Error GoTo Err

    mEmptyBill = EmptyBill
    mBillID = BillID
    
    Call LoadBill(nCount)
    If EmptyBill Or PreView Then
        Call BillPreView
    Else
        Call BillPrint
    End If
    Exit Sub
    
Err:
    MsgBox "错误:" & Err.Number & " " & Err.Description & " " & Err.Source, vbExclamation, Err.Number

End Sub

Public Sub LoadBill(Optional nCount As Integer = -1)
    Dim i As Integer, m As Integer, n As Integer, strValue As String, strsql As String
        
    If Not mEmptyBill Then
        
    Else
        mTotalPage = 1
    End If
    Exit Sub
    
End Sub

Public Sub BillPrint()
    Dim i As Integer
    
    On Error GoTo error
    
    For i = 1 To mTotalPage
        ShowBillData i, True: Printer.EndDoc
    Next
    
    Exit Sub
    
error:
    MsgBox " 打印错误!" & vbCrLf & Err.Description, vbExclamation, App.EXEName
    
End Sub

Public Sub BillPreView()
    
    'On Error GoTo error
    

    Exit Sub
error:
    MsgBox "打印错误!" & vbCrLf & Err.Description, vbExclamation, App.EXEName
End Sub

'计算总页数
Public Function TotalPage() As Integer
End Function

Private Sub PrintText(PrintObj As Object, CX As Single, CY As Single, ByVal strPrint As String)
    Dim UFormat As Long, strFormat As String
    Dim F1 As Boolean, F2 As Boolean, F3 As Boolean, F4 As Boolean
        
    On Error GoTo error
    
    If strPrint = "" Then Exit Sub
        
    If strFormat <> "" Then
    
        F1 = InStr(strFormat, "[去小数点]")
        strFormat = Replace(strFormat, "[去小数点]", "", 1, -1, vbTextCompare)
        
        F2 = InStr(strFormat, "[大写金额]")
        strFormat = Replace(strFormat, "[大写金额]", "", 1, -1, vbTextCompare)
        
        F3 = InStr(strFormat, "[大写数字]")
        strFormat = Replace(strFormat, "[大写数字]", "", 1, -1, vbTextCompare)
        
        F4 = InStr(strFormat, "[仅数字]")
        strFormat = Replace(strFormat, "[仅数字]", "", 1, -1, vbTextCompare)
        
        strPrint = Format(strPrint, strFormat)
    
        If F1 Then
            strPrint = Replace(strPrint, ".", "", 1, -1, vbTextCompare)
        ElseIf F2 Then
        End If
        
    End If
    
    With PrintObj
        
        mrect.Left = .ScaleX(CX, .ScaleMode, vbPixels)
        mrect.Top = .ScaleY(CY, .ScaleMode, vbPixels)
        DrawText .hdc, strPrint, -1, mrect, UFormat
        
    End With
    
    Exit Sub
error:
    MsgBox "打印错误!" & vbCrLf & Err.Description, vbExclamation, , vbExclamation, App.EXEName
End Sub

Public Sub ShowBillData(Page As Integer, Optional OutPutToPrinter As Boolean = False)
    Dim PrintObj As Object
    Dim i As Integer, j As Integer, SumField As String, SumData As Double, strValue As String
    
    On Error GoTo error
    
    Exit Sub
error:
    MsgBox "打印错误!" & vbCrLf & Err.Description, vbExclamation, App.EXEName
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -