My program has a splitcontainer within the form. Panel1 has a button that when clicked should save panel2 as a picture (ideally a jpg). I have a couple problems with the code I’m using.
private void btnSave_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(splitContainer1.Panel2.Width * 2, splitContainer1.Panel2.Height);
splitContainer1.Panel2.DrawToBitmap(bmp, splitContainer1.Panel2.Bounds);
bmp.Save(@"C:\Test.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
Here are the issues with my code that I’m curious about.
- if I use it as is, I get a jpg file saved out correctly but it contains additional black around the sides.

- If I change the last line of code to omit System.Drawing.Imaging.ImageFormat.Jpeg I get a picture with two clear boxes on either side which is still not what I want. (They’re clear but they are still there).

How can I get just the jpg file saved without the extra area around the panel?
EDIT:
Several people have pointed out my call of Splitcontainer1.panel2.width * 2. If I do not multiply the width by two I only get half of the actual panel2 like below, and it still has the unwanted blackbars/clearbars:

It looks like you are explicitly making the Bitmap too wide:
Just make it:
Also, you are specifying the bounds incorrectly. they represent the rectangle within the bitmap to draw in. Your call should probably be: