Click here to Skip to main content
15,796,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I want to print the data in a panel control in C# windows application.
I'm using the following code to get the printing area:

Bitmap MemoryImage;
       public void GetPrintArea(Panel pnl)
           MemoryImage = new Bitmap(pnl.Width, pnl.Height);
           Rectangle rect = new Rectangle(0, 0, pnl.Width, pnl.Height);
           //MemoryImage.SetResolution(100f, 100f);
           pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height));


       void printDoc1_PrintPage(object sender, PrintPageEventArgs e)
           Rectangle pagearea = e.PageBounds;
           e.Graphics.DrawImage(MemoryImage, 0, 0);
           //MemoryImage.SetResolution(200f, 200f);

But when printing, the quality of document is very poor, labels and images are not clear on print. How can I get the clear print?

Thank you.
Updated 24-Sep-12 22:24pm
Rajesh Anuhya 25-Sep-12 3:25am    
Edited : Pre Tags Added


Go through the below links, this may helps you.


Share this answer
add this namespace

using System.Drawing.Printing;
using System.IO;

class label variable

System.Drawing.Bitmap memoryimage;

write this code printbutton_click event

PrintDialog myprintdialog = new PrintDialog();
                memoryimage = new System.Drawing.Bitmap(panelprint.Width, panelprint.Height);
                panelprint.DrawToBitmap(memoryimage, panelprint.ClientRectangle);
                if (myprintdialog.ShowDialog() == DialogResult.OK)
                    System.Drawing.Printing.PrinterSettings value;
                    value = myprintdialog.PrinterSettings;
                    myprintdialog.Document = printDocument1;
                    printDocument1.PrintController = new StandardPrintController();
                    panelprint.BackColor = Color.White;

<pre lang="cs">private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
           e.Graphics.DrawImage(memoryimage, -2, 30);

where panelprint is the name of panel

I think this is helpfull to u..........
Sham :)
Share this answer
Shambhoo kumar 25-Sep-12 3:33am    
is this helpfull to u then u Accept my solution........
Zukiari 25-Sep-12 3:58am    
Thank you for your post.
I'm getting the panel data to the printer, problem is that I'm getting blurred print. I want to improve the clarity of the print. Is there any way???

Thank you.
Shambhoo kumar 25-Sep-12 4:52am    
this code also improve ur printing clarity......
Shambhoo kumar 27-Sep-12 2:35am    
hey frnd your problem is solved or not .if solved then how u reply me...

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