This will help:
Bitmap getControlSurface(Control ctl)
{
bitmap = new Bitmap(ctl.Width, ctl.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
Point pScreen = PointToScreen(ctl.Location);
g.CopyFromScreen(pScreen, Point.Empty, ctl.Size);
}
return bitmap;
}
If you know when the surface has been refreshed you can use it like this:
if ( pictureBox1.Image != null) pictureBox1.Image.Dispose();
pictureBox1.Image = getControlSurface(pictureBox1);
The only catch is that the PictureBox
actually must be completely visible on the screen!
2
solved How to cache the image of the control?