Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make scale up the panel with picture box, textbox, and label following the print page but scale up only panel not with picture box, textbox, and label. Can you help me to finish it.

What I have tried:

public partial class Form1 : Form
   {
       Bitmap memoryimg;
       PrintPreviewDialog printprvw = new PrintPreviewDialog();
       PrintDocument printdoc = new PrintDocument();
       Panel pannel;

       public Form1()
       {
           InitializeComponent();
       }
       private void button1_Click(object sender, EventArgs e)
       {
           panel1.Size = new Size(794, 1123);
           Print(this.panel1);
       }

       private void Print(Panel pn1)
       {
           PrinterSettings ps = new PrinterSettings();
           pannel = pn1;
           getprintarea(pn1);
           printprvw.Document = printdoc;
           printdoc.PrintPage += new PrintPageEventHandler(pntdoc_printpage);
           printprvw.ShowDialog();
       }

       private void pntdoc_printpage (object sender, PrintPageEventArgs e)
       {
           Rectangle pagearea = e.PageBounds;
           e.Graphics.DrawImage(memoryimg, 0,0);
       }

       private void getprintarea(Panel pn1)
       {
         memoryimg = new Bitmap(pn1.Width, pn1.Height);
         pn1.DrawToBitmap(memoryimg, new Rectangle(0,0,pn1.Width,pn1.Height));
       }

   }
}
Posted
Updated 6-Sep-18 17:50pm
Comments
Richard MacCutchan 5-Sep-18 5:24am    
You first need to get the dimensions of all your controls, and the spacing between them. Then get the dimensions of the page that you are going to print on. From there you can calculate whether you need to scale up or down on the final page. Try making a drawing on a piece of paper to visualise what you need to do.
Member 13964139 6-Sep-18 23:47pm    
Okey thank you, i did that and i win the solution.

1 solution

namespace PrintingWFP
{
    public partial class Form1 : Form
    {
        Bitmap memoryimg;
        PrintPreviewDialog printprvw = new PrintPreviewDialog();
        PrintDocument printdoc = new PrintDocument();
        Panel pannel;
        public Form1()
        {
            InitializeComponent();
        }

        private void Print(Panel pn1)
        {
            PrinterSettings ps = new PrinterSettings();
            pannel = pn1;
            getprintarea(pn1);
            printprvw.Document = printdoc;
            printdoc.PrintPage += new PrintPageEventHandler(pntdoc_printpage);
            printprvw.ShowDialog();
            panel1.Size = new Size(395, 642);
            panel1.Visible = true;
        }

        private void pntdoc_printpage(object sender, PrintPageEventArgs e)
        {
            Rectangle pagearea = e.PageBounds;
            e.Graphics.DrawImage(memoryimg, 0, 0);
            PrintPreviewDialog pre = new PrintPreviewDialog();
         
        }

        private void getprintarea(Panel pn1)
        {
            memoryimg = new Bitmap(pn1.Width, pn1.Height);
            pn1.DrawToBitmap(memoryimg, new Rectangle(0, 0, pn1.Width, pn1.Height));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
            panel1.Size = new Size(794, 1123);
            Print(this.panel1);
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900