Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7018203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:00:51+00:00 2026-05-27T23:00:51+00:00

My program has a splitcontainer within the form. Panel1 has a button that when

  • 0

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.

  1. if I use it as is, I get a jpg file saved out correctly but it contains additional black around the sides.enter image description here
  2. 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).
    enter image description here

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:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:00:52+00:00Added an answer on May 27, 2026 at 11:00 pm

    It looks like you are explicitly making the Bitmap too wide:

    splitContainer1.Panel2.Width * 2
    

    Just make it:

    splitContainer1.Panel2.Width
    

    Also, you are specifying the bounds incorrectly. they represent the rectangle within the bitmap to draw in. Your call should probably be:

    Bitmap bmp = new Bitmap(splitContainer1.Panel2.Width, splitContainer1.Panel2.Height);
    splitContainer1.Panel2.DrawToBitmap(bmp, new Rectangle(0,0,splitContainer1.Panel2.Bounds.Width,splitContainer1.Panel2.Bounds.Height));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program has a button which when clicked opens an openfiledialog to choose a
My program has to read files that use various encodings. They may be ANSI,
My program has two threads: Main execution thread that handles user input and queues
What do I need to do to save an image my program has generated
I have an application that seems to throw exceptions only after the program has
My program has a list of tabs that each contain a list of people.
My program has been working perfectly so far, but it turns out that I've
My program has a handful of settings that need to be established before it
My program has one button, and the other one is a JTextField. The action
My program has a component - dubbed the Scheduler - that lets other components

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.