Как печатать с помощью vb.net на бумаге с фиксированной шириной и динамической высотой - PullRequest
2 голосов
/ 10 ноября 2011

Я занимаюсь разработкой приложения для торговых точек (POS) в VB.NET и .NET Framework 3.5, в котором можно одновременно покупать несколько предметов. Мне нужно напечатать все элементы: их код, количество названий, цену в виде строки-столбца.

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.

Как это можно сделать?

1 Ответ

4 голосов
/ 11 ноября 2011

Стандартная печать 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...