printDocument 打印的时候,第一次打印没有问题,但是之后再打印的时候就成空白页了。重新启动程序的时候又好了,怎么回事啊
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
Graphics g = null;
e.HasMorePages = true;
PaperSize pSize = new PaperSize();
pSize.Width = 5;
pSize.Height = 3;
this.printDocument1.DefaultPageSettings.PaperSize = pSize;
g = e.Graphics;
MultiFormatWriter multiWriter = new MultiFormatWriter();
Brush br = new SolidBrush(Color.Black);
Font strFont = new Font("黑体", 10, FontStyle.Bold);
StringBuilder striInfo = new StringBuilder();
striInfo .Append(dtPrint.Rows[iPrint]["R_NO"].ToString() + " ");
striInfo .Append(dtPrint.Rows[iPrint]["NAME"].ToString() + "(" + dtPrint.Rows[iPrint]["SEX"].ToString() + ") ");
striInfo .Append(dtPrint.Rows[iPrint]["AGE"].ToString() + "(岁)");
g.DrawString(striInfo .ToString(), strFont, br, new Point(20, 30));
BitMatrix bm = multiWriter.encode(dtPrint.Rows[iPrint]["NO"].ToString(), BarcodeFormat.CODE_128, 110, 35);
Image barCode = new BarcodeWriter().Write(bm);
g.DrawImage(barCode, new Point(20, 50));
striInfo = new StringBuilder();
striInfo .Append(dtPrint.Rows[iPrint]["NO"].ToString());
g.DrawString(striInfo .ToString(), strFont, br, new Point(20, 90));
if (iPrint == dtPrint.Rows.Count - 1)
{
e.HasMorePages = false;
g.Dispose();
}
iPrint++;
this.Refresh();
g.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}