请问循环打印该怎么写?

XiaoYi96 2018-05-08 11:01:57
我第一种写法打印一张可以,但是循环打印两张的时候,打停机一直提示正在,打印,然后就没反应了!!!请问哪位大神
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(pictureBox1.Image, 10, 20);
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
string bh = dt.Rows[i]["开剪布号"].ToString();
Bitmap[] maps = new Bitmap[2];
maps[0] = (Bitmap)zftuhxzh.GetDimensionalCode(bh);//字符串转二维码
maps[1] = (Bitmap)zftuhxzh.sss("成品号:"+bh, textBox40.Font);//字符串转图片
pictureBox1.Image = zftuhxzh.MergerImg(maps);//两张图片拼接
e.Graphics.DrawImage(pictureBox1.Image, 10, 20);
}

}
...全文
511 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanghao1 2018-05-10
  • 打赏
  • 举报
回复
按F11运行跟踪,看看到哪一个语句发生了这个提示错误。
xuzuning 2018-05-08
  • 打赏
  • 举报
回复
printDocument1_PrintPage 用 e.HasMorePages = true; 来控制是否打印下一页 你的多页数据的产生,要写成一个方法,按传入的页号,每次返回一页数据,或直接绘制在传入的 Graphics 中
秋的红果实 2018-05-08
  • 打赏
  • 举报
回复
调试下,监控下 bh,maps,pictureBox1有没有值?
c02645 2018-05-08
  • 打赏
  • 举报
回复

int printPage=0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
              var i=printPage;
                string bh = dt.Rows[i]["开剪布号"].ToString();
                Bitmap[] maps = new Bitmap[2];
                maps[0] = (Bitmap)zftuhxzh.GetDimensionalCode(bh);//字符串转二维码
                maps[1] = (Bitmap)zftuhxzh.sss("成品号:"+bh, textBox40.Font);//字符串转图片
                pictureBox1.Image = zftuhxzh.MergerImg(maps);//两张图片拼接
                e.Graphics.DrawImage(pictureBox1.Image, 10, 20);
               printPage++;
                if ( dt.Rows.Count <= printPage)
                {
                    e.HasMorePages = false;
                }
                else
                {
                    e.HasMorePages = true;         //重复调用PrintPage事件
                }
        }
XiaoYi96 2018-05-08
  • 打赏
  • 举报
回复
引用 2 楼 xuzuning 的回复:
printDocument1_PrintPage 用 e.HasMorePages = true; 来控制是否打印下一页 你的多页数据的产生,要写成一个方法,按传入的页号,每次返回一页数据,或直接绘制在传入的 Graphics 中
我在for循环里加上e.HasMorePages = true;这句话之后,他就无限循环打印,停不下来了!!!!
XiaoYi96 2018-05-08
  • 打赏
  • 举报
回复
引用 1 楼 From_TaiWan 的回复:
调试下,监控下 bh,maps,pictureBox1有没有值?
调试了,有值得。我需求是一张纸打印一个二维码,我想用这种循环的方式,打印出两张纸两个二维码来。然后就卡着不动了

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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