简体   繁体   English

在vb.net中打印收据

[英]Print receipt in vb.net

收据

I am trying to print the above receipt using vb.net. 我正在尝试使用vb.net打印以上收据。 However, as seen in the image, the amount figure appears on a new line. 但是,如图所示,金额数字显示在新行上。 What am I doing wrong? 我究竟做错了什么?

Below is the code I use: 下面是我使用的代码:

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

There are three possibilities: 有三种可能性:

  • Your column qty (column idx 4) contains a string that has a newline in it. 列qty(列idx 4)包含一个包含换行符的字符串。 If this is the case, you can just Trim() the value before joining the values. 如果是这种情况,您可以在加入值之前只对值进行Trim()
  • Your column amount contains many spaces, or begins with a newline character. 您的列数包含许多空格,或以换行符开头。 If this is the case, you can also fix it by using Trim() , this time on the variable amount before joining the values. 如果是这种情况,您还可以使用Trim()来修复它,这次是在连接值之前对可变amount进行修复。
  • It's something else that I haven't thought of yet :). 这是我尚未想到的其他事情:)。

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

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