【问题标题】:How to print using vb.net on paper with fixed-width and dynamic height如何使用 vb.net 在具有固定宽度和动态高度的纸张上打印
【发布时间】:2011-12-26 11:00:24
【问题描述】:

我正在使用 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 还是 WPF? WPF 有一些不错的打印功能,例如 FlowDocumentScrollViewer 等。
  • 不知道会使用什么类型的打印机?所以,我试图让它覆盖大多数打印机,我知道这些打印机有驱动程序,它们可以像其他喷墨或台式喷墨打印机一样访问。
  • 我正在使用使用 vb.net framework 3.5 的 windows 窗体应用程序

标签: .net vb.net printing


【解决方案1】:

标准 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    • 2021-10-19
    • 2017-09-30
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多