//necessary function to create bitmap of form
[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll", ExactSpelling = true)]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("gdi32.dll", ExactSpelling = true)]
public static extern IntPtr BitBlt(IntPtr hDestDC, int x, int y,
int nWidth, int nHeight, IntPtr hSrcDC,
int xSrc, int ySrc, int dwRop);
public static Bitmap GetFormImage(System.Windows.Forms.Form frm)
{
Graphics g = frm.CreateGraphics();
Size s = frm.Size;
Bitmap formImage = new Bitmap(s.Width, s.Height, g);
Graphics mg = Graphics.FromImage(formImage);
IntPtr dc1 = g.GetHdc();
IntPtr dc2 = mg.GetHdc();
BitBlt(dc2, 0, 0, frm.ClientRectangle.Width, frm.ClientRectangle.Height, dc1, 0, 0, 13369376);
g.ReleaseHdc(dc1);
mg.ReleaseHdc(dc2);
return formImage;
}
No comments:
Post a Comment