Skip to content

Instantly share code, notes, and snippets.

@felipebaltazar
Created July 4, 2018 17:05
Show Gist options
  • Save felipebaltazar/530d426fe66152c6038fb570df386601 to your computer and use it in GitHub Desktop.
Save felipebaltazar/530d426fe66152c6038fb570df386601 to your computer and use it in GitHub Desktop.
private Bitmap CaptureControl(Control control)
{
Bitmap controlBmp;
using (var g1 = control.CreateGraphics())
{
controlBmp = new Bitmap(control.Width, control.Height, g1);
using (var g2 = Graphics.FromImage(controlBmp))
{
var dc1 = g1.GetHdc();
var dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, control.Width, control.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
}
}
return controlBmp;
}
[DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment