private const int WM_PRINT = 0x0317;
private const int PRF_CLIENT = 0x00000004;
private const int PRF_CHILDREN = 0x00000010;
public Bitmap PrintWindowEx()
{
Bitmap bmp = null;
Graphics gr = null;
IntPtr hdc = IntPtr.Zero;
try
{
bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, this.CreateGraphics());
gr = Graphics.FromImage(bmp);
hdc = gr.GetHdc();
IntPtr wParam = hdc;
IntPtr lParam = new IntPtr(PRF_CLIENT | PRF_CHILDREN);
Message msg = Message.Create(this.Handle, WM_PRINT, wParam, lParam);
this.WndProc(ref msg);
}
catch { }
finally
{
if (gr != null)
{
if (hdc != IntPtr.Zero)
gr.ReleaseHdc(hdc);
gr.Dispose();
}
}
return bmp;
}