Windows应用程序在打印后关闭

kil*_*s88 0 vb.net windows printing

我创建了一个具有打印功能的POS应用程序 该应用程序运行良好,也可以打印.唯一的问题是,它在打印后关闭.我在用户范围定义了设置.当我禁用打印时,一切都很完美.知道可能是什么原因?我的打印代码如下:

 Sub PrintSlip(ByVal tender As Decimal, ByVal change As Decimal)
    Dim P As New PrinterClass(Application.StartupPath)
    With P
        'Printing Logo
        .RTL = False
        .PrintLogo()


        'Printing Title
        .FeedPaper(4)
        .AlignCenter()
        .BigFont()
        .Bold = True
        .WriteLine("Sales Receipt")
        .Bold = False
        .GotoSixth(6)
        .WriteLine(My.Settings.TransNo)
        'Printing Date
        .GotoSixth(1)
        .NormalFont()
        .WriteChars("Date:")
        .WriteLine(DateTime.Now.ToString)
        .DrawLine()
        .GotoSixth(1)
        .WriteChars("Store:")
        .GotoSixth(2)
        .WriteChars(My.Settings.StoreName)
        .GotoSixth(3)
        .WriteChars("VAT No.")
        .GotoSixth(4)
        .WriteChars(My.Settings.VatNo)
        .GotoSixth(5)
        .WriteChars("Cashier:")
        .GotoSixth(6)
        .WriteChars(My.Settings.User)
        .WriteLine("")
        .GotoSixth(1)
        .DrawLine()
        .FeedPaper(2)

        'Printing Header
        .GotoSixth(1)
        .WriteChars("#")
        .GotoSixth(2)
        .WriteChars("Description")
        .GotoSixth(5)
        .WriteChars("QTY")
        .GotoSixth(6)
        .WriteChars("Sub Total")
        .WriteLine("")
        .DrawLine()
        '.FeedPaper(1)

        'Printing Items

        Dim i As Integer
        For i = 1 To Form1.DataGridView1.RowCount - 1
            .GotoSixth(1)
            .WriteChars(i)
            .GotoSixth(2)
            .WriteChars(Form1.DataGridView1.Rows(i - 1).Cells(2).Value)
            .GotoSixth(5)
            .WriteChars(Form1.DataGridView1.Rows(i - 1).Cells(3).Value)
            .GotoSixth(6)
            .WriteChars(My.Settings.currency & Form1.DataGridView1.Rows(i - 1).Cells(5).Value)
            .WriteLine("")
        Next

        'Printing Totals
        .NormalFont()
        .DrawLine()
        .GotoSixth(5)
        .WriteChars("TOTAL Inc VAT")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(My.Settings.Cash, 2))
        .WriteLine("")
        .GotoSixth(5)
        .WriteChars("VAT @ " & My.Settings.vat & "%")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(My.Settings.Cash * (My.Settings.vat / 100), 2))
        .WriteLine("")
        .GotoSixth(5)
        .WriteChars("Cash")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(tender, 2))

        .WriteLine("")
        .GotoSixth(5)
        .WriteChars("Change")
        .GotoSixth(6)
        .WriteChars(My.Settings.currency & Math.Round(change, 2))

        .WriteLine("")
        .DrawLine()
        .GotoSixth(1)
        .WriteChars(My.Settings.EndSlip)



        .CutPaper()

        'Ending the session
        .EndDoc()
    End With
    End
End Sub
Run Code Online (Sandbox Code Playgroud)

Rei*_*n S 6

您已经End放置了End With,这将强制应用程序停止.删除它应该可以解决您的问题!

MSDN参考:

您可以将End语句放在过程中的任何位置,以强制整个应用程序停止运行.End将关闭使用Open语句打开的所有文件,并清除所有应用程序的变量.只要没有其他程序保持对其对象的引用并且其代码都没有运行,应用程序就会关闭.