.net - 如何使用vb.net在固定宽度和动态高度的纸张上打印

标签 .net vb.net printing

我正在 VB.NET 和 .NET Framework 3.5 中开发一个销售点 (POS) 应用程序,可以一次购买多个商品。我需要以行列方式打印所有商品:它们的代码、名称数量、价格。

SHOP NAME            date
==========           =====
SL   CODE      NAME     QTY      PRICE
==   =====     =====    ===      =====
1    ANC-059   Pencil   1        $2.00
2    ASNC-009  Pencil   1        $2.00
3    ASNC-09   Pencil   1        $2.00
4    ASNC-009  Pencil   1        $2.00

页面的宽度是固定的,但高度是动态的。

打印输出将打印在 POS 系统中通常使用的卷纸上。

如何做到这一点?

最佳答案

标准 winforms 打印:

Try
    'Set up the document for printing and create a new PrintDocument object.
    Dim pd As New Printing.PrintDocument
    'Set the event handler for the printpage event of the PrintDocument.
    AddHandler pd.PrintPage, AddressOf pd_PrintPage
    'Set the printer name.
    pd.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
    'Print the document by using the print method for the PrintDocument, which triggers the PrintPage event
    pd.Print()  
Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try


'The PrintPage event is raised for each page to be printed.
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As Printing.PrintPageEventArgs)
    'Set up the default graphics object that will be used to do the actual printing.
    Dim g As Graphics
    g = ev.Graphics

    Dim tHeight as Double
    Dim txt as String = "My text goes here"
    g.DrawString(txt, myFont, myBrush, xPosition, yPosition, StringAlignment.Near)
    'Measure the height (on the page) of the item that you have just drawn, so that
    'you can place the next item below it.
    tHeight = g.MeasureString("Customer", fntBlue).Height()

    txt = "My new line of text"
    g.DrawString(txt, myFont, myBrush, xPosition, yPosition + tHeight, StringAlignment.Near)

    '.....continue printing other items
End Sub

关于.net - 如何使用vb.net在固定宽度和动态高度的纸张上打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8084866/

相关文章:

python - 如何打印到 .txt

.net - Intellisense 忽略程序集引用

c# - 如何使用 Tab 在 winform 属性网格的属性之间移动

c# - 在文本框中拖动文件或文件夹? C#

C#/VB.NET : Howto improve anti-alias quality

使用 fmt::Display 打印

html - IE8 中的旋转图像打印

.net - 在 .NET 中播放 OGG、MP4

c# - System.IO 与 VisualBasic.FileIO

c# - 将 C# 代码转换为 VB.net