开发者

Print data in a listview to look like an invoice

I have created a simple POS syste开发者_Python百科m and want to print the data in a listview consisting of products prices and quantity.

I wish to add the logo of the company at the very top and then the data in the columns that follow.


You can try using PrintDocument of .NET, like this:

   try {
        // If you want a preview use the PrintPreviewDialog
        PrintPreviewDialog preview = new PrintPreviewDialog();

        PrintDocument document = new PrintDocument();
        document.PrintPage += new PrintPageEventHandler(document_PrintPage);

        preview.Document = document;
        // Then show the dialog window.
        preview.Show();

        // Otherwise, just call the document.Print();

   } catch {
       throw;

   }

And have your printpage event like this, with this you can get the values from your listview control and format the layout as necessary to look much like an invoice:

    protected void document_PrintPage(object sender, PrintPageEventArgs ev) {
        Font printFont = new Font("Arial", 14);
        ev.Graphics.DrawString("Sample String", printFont, Brushes.Black, ev.MarginBounds.Left, ev.MarginBounds.Top, new StringFormat());
    }

This will directly print the text you want, but if you want to select the printer first, you may want to use the PrintDialog of .NET.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜