Transform a content into an image

1

I'm creating a Windows Forms project to help my company generate automated email signatures for our contributors.

I have in the case a single windows forms that contains a Tab Control, with Data and Preview. In the preview tab there is a PictureBox with some Labels above it that is where the data of the collaborator will be inserted.

My question is, how can I get the entire contents of this Preview tab saved in an image? (.jpg, .png, etc.)

Here are sample images below:

    
asked by anonymous 18.04.2016 / 16:33

1 answer

1

One way would be to use the Bitmap and Graphics classes to make a screenshot . I have not tested it and I do not know if it will work, but here is a code that shows an example of how to screenshot of your entire desktop - maybe you can adapt it to just your program:

//Criar um novo bitmap.
var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                               Screen.PrimaryScreen.Bounds.Height,
                               PixelFormat.Format32bppArgb);

// Criar um objecto de graphics do bitmap.
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

// Tira a screenshot do canto superior esquero até o canto inferior direito
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                            Screen.PrimaryScreen.Bounds.Y,
                            0,
                            0,
                            Screen.PrimaryScreen.Bounds.Size,
                            CopyPixelOperation.SourceCopy);

// Salvar o screenshot na pasta desejada
bmpScreenshot.Save("Screenshot.png", ImageFormat.Png);

Inspired by this answer from SOen.

    
20.04.2016 / 18:42