我正在尝试在 for 循环中打印,在该循环中必须打印组框,直到条件满足。
//代码:
private void btnPrint_Click(object sender, EventArgs e)
{
for (int i = 1; i <= Convert.ToInt32(lblTotalBox.Text); i++)
{
lblBoxNumber.Text = i.ToString();
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
PaperSize paperSize = new PaperSize("MyCustomSize", 100, 65);
paperSize.RawKind = (int)PaperKind.Custom;
printDocument1.DefaultPageSettings.PaperSize = paperSize;
using (Graphics g = e.Graphics)
{
using (new Font("Arial", 16))
{
float x = new float();
float y = new float();
x = e.MarginBounds.Left;
y = e.MarginBounds.Top;
Bitmap bmp = new Bitmap(350, 400);
grpReceipt.DrawToBitmap(bmp, new Rectangle(0, 0, 350, 400));
e.Graphics.DrawImage(bmp, x, y);
}
}
}
表格图像:
当我尝试运行上面的代码时,它不会给我任何错误,但第一次打印工作正常,其他都是空的。
我哪里错了?