Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following code for printing from a panel
C#
public void PrepareImage()
 Graphics graphic = panel2.CreateGraphics();
            Size s = panel2.Size;
            memImage = new Bitmap(s.Width, s.Height, graphic);
            Graphics memGraphic = Graphics.FromImage(memImage);
            IntPtr dc1 = graphic.GetHdc();
            IntPtr dc2 = memGraphic.GetHdc();
            BitBlt(dc2, 0, 0, panel2.ClientRectangle.Width,
            panel2.ClientRectangle.Height, dc1, 0, 0, SRCCOPY);
            graphic.ReleaseHdc(dc1);
            memGraphic.ReleaseHdc(dc2);   
        }    
        private void btnprint_Click(object sender, EventArgs e)
        {
            PrepareImage();
            printDocument1.Print();
        }
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Bitmap bmp=new Bitmap(panel2.Width, panel2.Height);
            panel2.DrawToBitmap(bmp, new Rectangle(0, 0, panel2.Width, panel2.Height));
            e.Graphics.DrawImage(bmp, 0, 0);
}


But it does n't print the entire panel (entire width is not coming).
Actually the panel exceeds the width of the form . I want the contents to be resized to fit in one page.
Posted
Updated 30-Jun-11 0:48am
v2

 
Share this answer
 
Your best bet would be to forget about creating an image of the panels and concentrate on creating a proper document from the information that is contained within the Panels. You can do this with the GDI+ API. Here[^] is the MSDN Article on that topic.

Hope this helps
 
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