[英]How to Print Listed invoices each on another (different) Page in C# windows form Application?
场景:
我在Windows表单应用程序上工作,我在datagridview中有今天的销售报告,在从datagridview选择for循环中的invoiceID后,我必须打印发票,但不同页面上的每个发票。 如何在打印时切换到下一页。
我的代码:
private void prnDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
CurrentY = 50;
CurrentX = 100;
for (int i = 0; i < dgvViewGeneralSaleReport.RowCount; i++)
{
if (dgvViewGeneralSaleReport.Rows[i].Cells[0].Value != " ")
{
invoiceID = Convert.ToInt32(dgvViewGeneralSaleReport.Rows[i].Cells[0].Value.ToString().Trim());
//// invoice design Start
leftMargin = 20;
// rightMargin = (int)e.MarginBounds.Right;
rightMargin = 830;
topMargin = (int)e.MarginBounds.Top;
bottomMargin = (int)e.MarginBounds.Bottom;
InvoiceWidth = (int)e.MarginBounds.Width;
InvoiceHeight = (int)e.MarginBounds.Height;
if (!ReadInvoice)
ReadInvoiceData();
SetInvoiceHead(e.Graphics); // Draw Invoice Head
SetOrderData(e.Graphics); // Draw Order Data
SetInvoiceData(e.Graphics, e); // Draw Invoice Data
//// invoice design End
ReadInvoice = true;
e.HasMorePages = true;
CurrentY = 50;
CurrentX = 100;
}
else
{
StopReading = true;
ReadInvoice = false;
e.HasMorePages = false;
break;
}
}
}
您需要将循环放在PrintPage
方法之外。 您开始打印的调用需要是循环中的调用。
基本上...
for (int i = 0; i < dgvViewGeneralSaleReport.RowCount; i++)
{
if (dgvViewGeneralSaleReport.Rows[i].Cells[0].Value != " ")
printDocument.Print();
}
在PrintPage
方法中,继续执行您现在所做的所有相同操作,只需要您还必须了解要打印的页面。
这里重要的一点是,它是对PrintPage
的单独调用,用于定义页面。 控制变量e.HasMorePages
是你告诉它继续前进的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.