printdocument打印问题只打印第一页

时间:2013-06-20 17:56:29

标签: c# .net winforms printing

我必须能够按列顺序打印ListView中的所有项目,如下所示:

开始:(约会) 结束日期) 班次:(轮班号) 销售:(销售)

它完全打印出我需要的内容,但它只打印第一页(或列表视图的前12行。但是,如果我将信息发送到消息框,它会发送所有列表视图内容,使其在打印中导致它不打印全部,但我无法弄明白。

private void btnPrint_Click(object sender, EventArgs e)
    {

        try
        {
            PrintDialog pd = new PrintDialog();
            PrintDocument MyPrintDocument = new PrintDocument();
            MyPrintDocument.PrintPage += new PrintPageEventHandler(this.PrintPageEvent);
            pd.PrinterSettings.PrintRange = PrintRange.AllPages;
            MyPrintDocument.PrinterSettings.PrintRange = PrintRange.AllPages;
            MyPrintDocument.Print();
        }
}


 private void PrintPageEvent(object sender, PrintPageEventArgs ev)
     {
        string text = null;
        for (int i = 0; i < listView4.Items.Count; i++)
        {
            text += "Start: " + listView4.Items[i].Text + Environment.NewLine + "End: " + listView4.Items[i].SubItems[1].Text + Environment.NewLine + "Shift Number: " + listView4.Items[i].SubItems[2].Text + Environment.NewLine + "Total Sales: " + listView4.Items[i].SubItems[3].Text + Environment.NewLine + "----------------------------" + Environment.NewLine;
        }
        MessageBox.Show(text);
        Font MyFont = new Font("Arial", 12);
        ev.Graphics.DrawString("------------------------------------" +
    Environment.NewLine + text +
    Environment.NewLine + "------------------------------------", MyFont, new SolidBrush(System.Drawing.Color.Black),
            (ev.PageBounds.Left), ev.PageBounds.Top);
       }

2 个答案:

答案 0 :(得分:2)

您应该指定PrintPageEventArgs.HasMorePages = true来打印多个页面。所以,在你的情况下,你只需这样做

ev.HasMorePages = true;

PrintPageEventArgs.HasMorePages财产 -

  • 获取或设置一个值,指示是否应打印其他页面。
  • 如果要打印其他页面,
  • 会返回true;否则,false
  • 默认值为false

答案 1 :(得分:1)

如果要在e.HasMorePages = true;方法处理程序中打印更多页面,则需要设置PrintPageEvent。根据{{​​3}},默认值为false