简体   繁体   English

Windows应用程序在打印后关闭

[英]Windows application closes after printing

I created a POS application with printing capability. 我创建了具有打印功能的POS应用程序。 The application works well and can also print. 该应用程序运行良好,也可以打印。 The only problem is that, it closes after printing. 唯一的问题是,它在打印后关闭。 I have settings defined at user scope. 我在用户范围内定义了设置。 When I disable printing, everything works perfectly. 当我禁用打印时,一切正常。 Any idea what could be the cause? 知道可能是什么原因吗? My printing code below: 我的打印代码如下:

 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

You have End placed after End With , which will force the application to stop. End放置在End With ,这将迫使应用程序停止。 Removing this should clear up your issue! 删除它应该可以解决您的问题!

From the MSDN reference : MSDN参考

You can place the End statement anywhere in a procedure to force the entire application to stop running. 您可以将End语句放在过程中的任何位置,以强制整个应用程序停止运行。 End closes any files opened with an Open statement and clears all the application's variables. End关闭使用Open语句打开的所有文件,并清除所有应用程序变量。 The application closes as soon as there are no other programs holding references to its objects and none of its code is running. 一旦没有其他程序保存对其对象的引用并且该程序的任何代码都未运行,该应用程序就会关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM