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

I'm having a panel in C# webform which contains images, labels and textboxes. I want to print the whole panel when a button is clicking. How can I do it? I'm not familiar with C# windows application. Anyone please help me...

Thank you.
Posted

Hi you can use this code:
private void doc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    Panel grd = new Panel();
    Bitmap bmp = new Bitmap(grd.Width, grd.Height, grd.CreateGraphics());
    grd.DrawToBitmap(bmp, new Rectangle(0, 0, grd.Width, grd.Height));
    RectangleF bounds = e.PageSettings.PrintableArea;
    float factor = ((float)bmp.Height / (float)bmp.Width);
    e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, bounds.Width, factor * bounds.Width);
}

and make a button and write this code:
private void button1_Click_1(object sender, EventArgs e)
       {
           System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
           doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(doc_PrintPage);
           doc.Print();
       }


Amir
 
Share this answer
 
v2
Comments
Zukiari 17-Sep-12 6:15am    
Thank you So much...
Shivani11jais 24-Apr-13 9:08am    
Thank u for this answer. It work properly.....

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