如何在多个页面上打印大图像 [英] how to print large image on multiple pages

查看:71
本文介绍了如何在多个页面上打印大图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发一个Windows项目。我有一个大的没有。图像。

我在图片框中显示这些图像。我有一个按钮来打印这个图片框。现在我的问题是如果图片框的大小增加,那么所有图片都没有显示在页面上。如果图片框的大小超过页面大小,那么我想在另一页面上显示休息图像。以下是代码



Hello everyone,
I am working on a windows project. where i have a large no. of images.
I show these images in a picture box. I have a button to print this picture box. Now my problem is if The size of picture Box is increase then all pictures not shown on page.If size of picture box is more than page size then I want to display rest images on another page. Below is the code

private void btn_prnt_Click(object sender, EventArgs e)
      {
          previewDlg = new PrintPreviewDialog();
          PrintDocument pd = new PrintDocument();
          //Add print-page event handler
          pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
          pd.Print();
      }
public void pd_PrintPage(object sender, PrintPageEventArgs ev)
      {
          float x = ev.MarginBounds.Left - 50;
          float y = ev.MarginBounds.Top - 70;
          float pageheight = ev.MarginBounds.Height;
          Bitmap bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
          int imgWidth=this.pictureBox1.Width;
          int imght = ev.MarginBounds.Height;
              this.pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, imgWidth, imght));
              ev.Graphics.DrawImage((Image)bmp, x, y);
          }

推荐答案

要打印另一页,您需要设置 e.HasMorePages 在PrintPage处理程序结束时为true。这将导致再次调用处理程序 - 因此您需要跟踪到目前为止已打印的内容,并根据该内容决定在当前页面上打印的内容以及当前页面是否是最后一页。



请参阅:绝对新手的.NET打印指南 [ ^ ]
To print another page you need to set e.HasMorePages to true at the end of your PrintPage handler. This will cause the handler to be called again - so you need to keep track of what you have printed so far and based on that decide what to print on the current page and also if the current page is the last page.

See: An absolute beginner's guide to printing in .NET[^]


这篇关于如何在多个页面上打印大图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆