我想打印到C#中的NextPageusing printdocument。我正在使用的代码继续将页数增加到无限循环。
我使用的代码如下:
PaperSize pze = new PaperSize("Custom Paper size", 800, 150);
public void Print()
{
printDocument1.DefaultPageSettings.PaperSize = pze;
printDocument1.Print();
}
int YHeight = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
panel1_Paint(sender, new PaintEventArgs(e.Graphics, this.ClientRectangle));
int heightOfPage = 150;
float pageHeight = e.MarginBounds.Height;
while (heightOfPage + 100 < pageHeight && YHeight < this.SaveBeforePrint.Count)
{
YHeight += 1;
heightOfPage += 20;
}
if (YHeight < this.SaveBeforePrint.Count)
{
e.HasMorePages = true;
return;
}
else
{
e.HasMorePages = false;
}
}
答案 0 :(得分:0)
您可以更改PrintPage方法,如下所示..
这里countInRow是每页要显示的行中条形码的数量..
int countInRow = 3; // number of barcode in a row on every page.
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
panel1_Paint(sender, new PaintEventArgs(e.Graphics, this.ClientRectangle));
int locCount = SaveBeforePrint.Count;
for (int i = 0; i < countInRow && i < locCount; i++)
{
SaveBeforePrint.RemoveAt(0); //remove the top element always
}
e.HasMorePages = (SaveBeforePrint.Count > 0);
}
你还需要在“panel1_Paint”方法中再做一次更改,更改for循环条件
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
.
.
.
for (int serial = 0; serial < SaveBeforePrint.Count && serial < countInRow; serial++)
{
// you code goes here..
}
.
.
.
}