簡體   English   中英

在vb.net中打印收據

[英]Print receipt in vb.net

收據

我正在嘗試使用vb.net打印以上收據。 但是,如圖所示,金額數字顯示在新行上。 我究竟做錯了什么?

下面是我使用的代碼:

Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim offset As Integer = 15
    Dim itemdesc As String = "Item".PadRight(30)
        Dim Pricedesc As String = "Price".PadRight(8)
        Dim qtydesc As String = "Qty".PadRight(5)
        Dim amtdesc As String = "Amount"
        Dim descline As String = itemdesc + Pricedesc + qtydesc + amtdesc
        e.Graphics.DrawString(descline, New Font("Courier New", 8, FontStyle.Regular), Brushes.Black, 25, 100 + offset)
        offset += 10
    Dim startx As Integer = 25
        Dim starty As Integer = 100

        Dim font As New Font("Courier New", 8, FontStyle.Regular)
        Dim item As String
        Dim price As String
        Dim qty As String
        Dim amount As String

    Dim productline As String
        For k As Integer = 0 To dgvSales.RowCount - 2

            item = dgvSales.Rows(k).Cells(1).Value.ToString.PadRight(30)
            price = dgvSales.Rows(k).Cells(3).Value.ToString.PadRight(8)
            qty = dgvSales.Rows(k).Cells(4).Value.ToString.PadRight(5)
            amount = dgvSales.Rows(k).Cells(5).Value.ToString
            productline = item + price + qty + amount
            e.Graphics.DrawString(productline, font, Brushes.Black, startx, starty + offset)
            offset += 20

        Next
End Sub

有三種可能性:

  • 列qty(列idx 4)包含一個包含換行符的字符串。 如果是這種情況,您可以在加入值之前只對值進行Trim()
  • 您的列數包含許多空格,或以換行符開頭。 如果是這種情況,您還可以使用Trim()來修復它,這次是在連接值之前對可變amount進行修復。
  • 這是我尚未想到的其他事情:)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM