Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m trying to print lage size of panel like(1024,700).but it not print all area of panel so plz help any one..
Posted
Comments
lukeer 1-Nov-12 3:21am    
Here[^] is a good hint of how to ask a question so you get a usable answer.

1 solution

panel is control it self
so, use this command

C#
PrintDialog myPrintDialog = new PrintDialog();
System.Drawing.Bitmap memoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(memoryImage, panel1.ClientRectangle);
if (myPrintDialog.ShowDialog() == DialogResult.OK)
{
    System.Drawing.Printing.PrinterSettings values;
    values = myPrintDialog.PrinterSettings;
    myPrintDialog.Document = printDocument1;
    printDocument1.PrintController = new StandardPrintController();
    printDocument1.Print();
}
printDocument1.Dispose();




or scale image if it's not fit into page
C#
private void panel1_Click(object sender, EventArgs e)
        {
            PrintDialog myPrintDialog = new PrintDialog();
            memoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);

//scaling into small size
            memoryImage.SetResolution(150, 150);
            panel1.DrawToBitmap(memoryImage, panel1.ClientRectangle);
            memoryImage.Save("E:/a.bmp");
            if (myPrintDialog.ShowDialog() == DialogResult.OK)
            {
                System.Drawing.Printing.PrinterSettings values;
                values = myPrintDialog.PrinterSettings;
           
                myPrintDialog.PrinterSettings.DefaultPageSettings.Landscape = true;
                printDocument1.DefaultPageSettings = myPrintDialog.PrinterSettings.DefaultPageSettings;

                myPrintDialog.Document = printDocument1;
                printDocument1.PrintController = new StandardPrintController();
                printDocument1.Print();


            }
            printDocument1.Dispose();
        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            SizeF sz = new SizeF(e.PageBounds.Width - e.MarginBounds.Width, e.PageBounds.Height - e.MarginBounds.Height);
            PointF p = new PointF((sz.Width) / 70, (sz.Height) / 70);
            e.Graphics.DrawImage(memoryImage, p);
        }

Note : I have tried to print in Papersize is A5

Happy Coding!
:)
 
Share this answer
 
v2
Comments
Shambhoo kumar 1-Jan-13 5:45am    
Your coding is good but it also not print all areas of panel..........
Aarti Meswania 1-Jan-13 6:38am    
image is big
you should resize/Scale it in a manner that it fits in page while printing
visit...
http://stackoverflow.com/questions/3489010/scaling-image-for-printing
http://www.codeproject.com/Articles/36990/An-Easy-Way-to-Resize-an-Image

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