printDocument 打印的时候,第一次打印没有问题,但是之后再打印的时候就成空白页了。重新启动程序的时候又好了,怎么回事啊

y794992006 2017-06-29 10:13:01
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;
}
}
...全文
1491 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
y794992006 2017-06-29
  • 打赏
  • 举报
回复
自己找到问题了 调用Print方法用这个就可以了 System.Drawing.Printing.PrintDocument pd3 = new PrintDocument(); pd3.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); pd3.Print();
y794992006 2017-06-29
  • 打赏
  • 举报
回复
求助求助,求大神帮忙看看……

3,405

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 设计模式
社区管理员
  • 设计模式
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧