-
using System;
-
using System.Drawing;
-
using System.Runtime.InteropServices;
-
using System.Windows.Forms;
-
-
public class ControlPainter
-
{
-
private const int
-
WM_PRINT = 0×317, PRF_CLIENT = 4,
-
PRF_CHILDREN = 0×10, PRF_NON_CLIENT = 2,
-
COMBINED_PRINTFLAGS = PRF_CLIENT | PRF_CHILDREN | PRF_NON_CLIENT;
-
-
[DllImport("USER32.DLL")]
-
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);
-
-
public static void PaintControl(Graphics graphics, Control control)
-
{ // paint control onto graphics
-
IntPtr hWnd = control.Handle;
-
IntPtr hDC = graphics.GetHdc();
-
SendMessage(hWnd, WM_PRINT, hDC, COMBINED_PRINTFLAGS);
-
graphics.ReleaseHdc(hDC);
-
}
-
}
-
-
<strong>TO USE IT:
-
</strong>
-
using (Form f = new MyForm()) {
-
Image i = new Image(f.Width, f.Height);
-
Graphics g = Graphics.FromImage(i);
-
ControlPainter.PaintControl(g, f);
-
}
Source
Reference
.net, drawing
This entry was posted
on Thursday, August 12th, 2010 at 4:41 pm and is filed under .NET, Image.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.