Modification of KeyboardP's answer. Modified to a static method so it can be used as a helper.
public static Bitmap ScreenShotaControl(Control aControl)
{
try
{
Bitmap bmp = new Bitmap(aControl.Width, aControl.Height);
aControl.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
return bmp;
}
catch (Exception)
{
throw;
}
}
Example usages are as follows:
Bitmap bmp = ScreenShotaControl(aControl);
Clipboard.SetImage(bmp); //to copy to clipboard
Bitmap bmp = ScreenShotaControl(aControl);
bmp.Save(@"C:\MyPanelImage.bmp"); //save to specified path
Bitmap bmp = ScreenShotaControl(aControl);
MemoryStream ms= new MemoryStream();
bmp.Save(ms, ImageFormat.Jpeg);
ContentType ct= new ContentType();
ct.MediaType = MediaTypeNames.Image.Jpeg;
MailMessage mail = new MailMessage();
mail.Attachments.Add(new Attachment(ms, ct)); //attach to email