如何在多个页面上打印大尺寸图片框 [英] How to print a large size picture Box 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);
          }





我是如何实现这一目标的。谢谢



how i achieve this. Thanks

推荐答案

Bitmap myBitmap1 = new Bitmap(myPicturebox.Width, myPicturebox.Height);

Now Print this picturebox image.

myPicturebox.DrawToBitmap(myBitmap1, new Rectangle(0, 0, myPicturebox.Width, myPicturebox.Height));

e.Graphics.DrawImage(myBitmap1, 0, 0);
Then dispose the bitmap to release the resources.
Now create the objects of the PrintDocument & PrintDialog.
System.Drawing.Printing.PrintDocument myPrintDocument1 = new System.Drawing.Printing.PrintDocument();
PrintDialog myPrinDialog1 = new PrintDialog();
Now create the PagePrint event of PrintDocument

myPrintDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(myPrintDocument2_PrintPage);
Then assing the PrintDocument object to PrintDialog.

myPrinDialog1.Document = myPrintDocument1;
Finally it will print the Image which is in the picturebox.

if (myPrinDialog1.ShowDialog() == DialogResult.OK)
{
               myPrintDocument1.Print();
}
The above code will ask you the printer name in which you can print the picture.

The the full code for printing the picture.

private void myPrintDocument2_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Bitmap myBitmap1 = new Bitmap(myPicturebox.Width, myPicturebox.Height);
            myPicturebox.DrawToBitmap(myBitmap1, new Rectangle(0, 0, myPicturebox.Width, myPicturebox.Height));
            e.Graphics.DrawImage(myBitmap1, 0, 0);
            myBitmap1.Dispose();
        }
        private void btnPrintPicture_Click(object sender, EventArgs e)
        {
            System.Drawing.Printing.PrintDocument myPrintDocument1 = new System.Drawing.Printing.PrintDocument();
            PrintDialog myPrinDialog1 = new PrintDialog();
            myPrintDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(myPrintDocument2_PrintPage);
            myPrinDialog1.Document = myPrintDocument1;
 
            if (myPrinDialog1.ShowDialog() == DialogResult.OK)
            {
               myPrintDocument1.Print();
            }
        }


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

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