在列表视图中打印数据看起来像发票

时间:2011-05-18 02:14:11

标签: c# listview printing

我创建了一个简单的POS系统,并希望在包含产品价格和数量的列表视图中打印数据。

我希望在顶部添加公司徽标,然后在后面的列中添加数据。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用.NET的 PrintDocument ,如下所示:

   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;

   }

并举办类似这样的printpage活动,您可以从listview控件中获取值,并根据需要格式化布局,使其看起来很像发票:

    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());
    }

这将直接打印您想要的文本,但如果您想先选择打印机,则可能需要使用.NET的 PrintDialog