VB.NET小报表(收据)打印

 

 

    ''' <summary>     ''' 打印收据     ''' </summary>     ''' <remarks></remarks>     Private Sub PrintReceipt()         Try             '调用更改默认打印机             Call changeDefaultPrinter(PrintDocType.Receipt)

            Dim PrintDoc As New Printing.PrintDocument

            AddHandler PrintDoc.PrintPage, AddressOf DrawReceipt '关键是这句话,当使用Print方法时,会自动调用DrawReceipt方法,这个方法是画小收据的过程,可以自定义.             PrintDoc.Print()

        Catch ex As Exception             MsgBox("Printing error!" & vbCrLf & "Please make sure your printer is valid!", 48)         End Try     End Sub

'这个函数的参数是固定的.用e变量来画出任何图形或文字,这样就可以打印到打印机去了.这个例子有点复杂,有空我再简化一下.

    ''' <summary>     ''' 画出Receipt,用于打印.收据,     ''' 临时使用,最后完善一个打印类     ''' </summary>     ''' <param name="sender"></param>     ''' <param name="e"></param>     ''' <remarks></remarks>     Private Sub DrawReceipt(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)

        Dim MyTitformat As New StringFormat         MyTitformat.Alignment = StringAlignment.Center         Dim MyTitformat_item As New StringFormat

        Dim MyConformat As New StringFormat         MyConformat.Alignment = StringAlignment.Near

        'e.Graphics.PageUnit = GraphicsUnit.Millimeter         e.Graphics.PageUnit = GraphicsUnit.Point         'e.Graphics.PageUnit = GraphicsUnit.Pixel         Dim MyTitFont1 As New Font("Arial", 21, FontStyle.Bold)   '标题字体         Dim MyTitFont2 As New Font("Arial", 12, FontStyle.Bold)   '标题字体         Dim MyConFont As New Font("Arial", 8, FontStyle.Regular)    '正文字体         Dim MyConFont1 As New Font("Arial", 9, FontStyle.Bold)    '正文字体         Dim MyLinePen As New Pen(Color.Black, 1)         Dim RecRow As Single = 0         RecRow = 1         Dim nPageH As Double = 0         Dim nPageW As Double = 0

        nPageH = nPh         nPageW = nPw         nPageW = 180         topW = nPageW

        ''左半侧三例的X坐标         Dim XL0 As Double = 0         Dim XL1 As Double = 0         Dim XL2 As Double = 0         Dim XL3 As Double = 0         Dim XL4 As Double = 0

        ''当前的Y坐标         Dim YCurrent As Double = 20         ''中间竖线的X坐标         Dim XLine As Double = 0

        ''每行文字的高度         Dim dHline As Double = 0

        ''当前打印的区域,主要用于控制描述打印的自动换行和换行后的高度         Dim CurRecF As RectangleF

        ''当前打印的字符         Dim sCurTPrintStr As String = ""

        ''用于保存打印公司信息时的打印宽度         Dim companyInfoW As Double = 230

        XLine = nPageW / 2 - 25         Me.itemnumW = 90         dItemDesW = 2         dItemQuantityW = 23         dItemPriceW = 52         allPriceW = 60

        XL0 = 0         XL1 = XL0 + Me.itemnumW         XL2 = XL1 + dItemDesW         XL3 = XL2 + Me.dItemQuantityW         XL4 = XL3 + Me.dItemPriceW

        'e.Graphics.DrawLine(Pens.Black, CInt(XL0), CInt(YCurrent), CInt(XL0 + nPageW), CInt(YCurrent))         'YCurrent = YCurrent + 1         'e.Graphics.DrawLine(Pens.Black, CInt(XL0), CInt(YCurrent), CInt(XL4 + dItemPriceW), CInt(YCurrent))

        Dim LogoIsExistence As Boolean = True         '先判断是否要在收据上打印Logo         If objSetup.Logo_Type = 1 Or objSetup.Logo_Type = 3 Then             If My.Computer.FileSystem.FileExists(Application.StartupPath.Trim & "/Pictures/LogoOnReceipt.TIF") Then                 LogoIsExistence = True

                Dim printLogo As Image = Image.FromFile(Application.StartupPath.Trim & "/Pictures/LogoOnReceipt.TIF")                 YCurrent = 10                 '画左侧Logo                 Dim xL As Single = 10.0F                 Dim yL As Single = Convert.ToSingle(YCurrent)                 e.Graphics.DrawImage(printLogo, xL, yL)             Else                 LogoIsExistence = False             End If         End If         'companyInfoW = e.PageSettings.PaperSize.Width

 

        '判断是否要在收据上打印公司信息         If objSetup.Logo_Type = 2 Or objSetup.Logo_Type = 3 Then             '打印公司信息

            '判断标题是否要打印:如果打印Logo的话公司名就不要打印             If

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值