how to print two panel in same form?

Copper Contributor

Im creating window form app i have two panel in same window form and when user print i want to print in two page panel1 into page1 and panel two in page2. i have tried this code and it prints well one page how to print the second panel in page two?

 

 

 

 

 

 

 

 

 

//print fucntion
  private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Margins margins = new Margins(100, 100, 100, 100);
            printDocument1.DefaultPageSettings.Margins = margins;

            Panel grd = new Panel();
            grd = panel1;
            Bitmap bmp = new Bitmap(grd.Width, grd.Height, grd.CreateGraphics());
            printDocument1.DefaultPageSettings.Landscape = true;

            grd.DrawToBitmap(bmp, new Rectangle(0, 0, grd.Width, grd.Height));
            RectangleF bounds = printDocument1.DefaultPageSettings.Bounds;
            e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, bounds.Width, bounds.Height);
        }

//print button
 private void button1_Click(object sender, EventArgs e)
        {

            printPreviewDialog1.Document = printDocument1; //Associate PrintPreviewDialog with PrintDocument.
            printPreviewDialog1.ShowDialog(); // Show PrintPreview Dialog

        }

 

 

 

 

 

 

 

 

1 Reply

Hi @CIWAAN,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang