Slight modification of Killercam's answer:
public static Bitmap takeComponentScreenShot(Control control)
{
// find absolute position of the control in the screen.
Control ctrl = control;
Rectangle rect = new Rectangle(Point.Empty, ctrl.Size);
do
{
rect.Offset(ctrl.Location);
ctrl = ctrl.Parent;
}
while (ctrl != null);
Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
return bmp;
}
This method will take screenshot immediately. For example, if you change visibility of a button within the panel just before calling this function, the bitmap will contain the button. If this is not desired, use keyboardP's answer.