我必须能够使用列名按顺序打印 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);
}