I have a form that has 2 panels. I’m trying to save the contents of Panel2 as an image. I saw a thread that talked about using the screen capture to do this, but I can’t find the thread anymore. Also read about using the DrawToBitMap method, but it’s from visual studio 2005 info, not sure if it’s the most current or suitable solution for this. So what do you recommend for saving my Panel2 as a picture, preferably a jpg?
UPDATE:
I implemented the code recommended below for the DrawToBitMap, but it saves half of my panel2 (the left half if that makes a difference).
Because it saved half my panel2, I multiplied the width call by ‘2’ to make it save the full form. Kind of a weird thing and doesn’t make sense to me since the width of panel 2 should be the full panel and not half of it?
//multiplies the width of panel2 call by 2 to make it save the full panel
Bitmap bmp = new Bitmap(splitContainer1.Panel2.Width * 2, splitContainer1.Panel2.Height);
splitContainer1.Panel2.DrawToBitmap(bmp, splitContainer1.Panel2.Bounds);
bmp.Save(@"C:\Test.bmp");
Control.DrawToBitMapis still supported in .Net 4. With the following caveats.From above link:
can override the OnPrint event and provide custom printing logic if
required.
The DrawToBitmap method has the following limitations:
allowable size varies by machine.
Tablet PC Edition 2005 operating system.
the TextBox is set to false.
border of a bitmap is drawn.
Edit Added example and image: