【问题标题】:Windows application closes after printingWindows 应用程序在打印后关闭
【发布时间】:2015-05-22 15:30:41
【问题描述】:

我创建了一个具有打印功能的 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

【问题讨论】:

    标签: vb.net windows printing


    【解决方案1】:

    您将End 放在End With 之后,这将强制应用程序停止。删除它应该可以解决您的问题!

    来自MSDN reference

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

    【讨论】:

    • @kilojoules88 正确的“谢谢”是单击最适合您的答案旁边的复选标记。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多