0

I want to save a panel screenshot by clicking the button. I try this

private void SPREMI_Click(object sender, EventArgs e)
{
    Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);
    panel1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
    bmp.Save(@"test.bmp");
}

As for the code, it is very good, but there is one problem: When you place the panel and the label on the image,on image only the panel will be visible to me.

This is how it look in program:

https://i.imgur.com/I5DFV.jpg

This is what I got when I save with this code:

enter image description here

Can any one help me I want when I save the image to look like in the program i.e. in this case I want to see label1

BPSK
  • 15
  • 5
  • Ok the first picture is 2 characters from spitting image the second is a green rectangle.. How is the picture getting in the panel – BugFinder Oct 28 '19 at 15:17
  • Possible duplicate of [C# Take ScreenShot of .net control within application and attach to Outlook Email](https://stackoverflow.com/questions/16000603/c-sharp-take-screenshot-of-net-control-within-application-and-attach-to-outlook) –  Oct 28 '19 at 15:19
  • This method you're using has lots of limitations https://stackoverflow.com/questions/8738054/how-can-i-save-a-panel-in-my-form-as-a-picture – Hirasawa Yui Oct 28 '19 at 15:20
  • @OlivierRogier In this case, we are the same, but this is not a duplicate, because I am not interested in making screenshots, but how to see everything in that shot. – BPSK Oct 28 '19 at 15:35
  • @OlivierRogier I want to create a screenshot where everything can be clearly seen, see the links above where I left pictures of what I want and what I get with the code I provided above – BPSK Oct 28 '19 at 15:44
  • Note that there is a [quirk](https://stackoverflow.com/questions/41865313/how-to-capture-all-the-items-inside-a-control/41873172#41873172) about the z-order.. – TaW Oct 28 '19 at 18:33
  • It seems that your first picture is not related to your second picture, right? Could you tell me your expected result picture? – Jack J Jun Oct 29 '19 at 01:50

2 Answers2

0

If you use PictureBox to hold a picture and you want save panel screenshot with label and PictureBox is on panel try this:

private void SPREMI_Click(object sender, EventArgs e)
{
    pictureBox1.Controls.Add(label1);
    Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);
    panel1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
    bmp.Save(@"test.bmp");
}
xKoSeMi
  • 1
  • 1
  • 2