#region 矢量图
private static System.Drawing.Imaging.Metafile mf;
const int WM_PRINT = 0x0317;
const int PRF_CHECKVISIBLE = 0x00000001,
PRF_NONCLIENT = 0x00000002,
PRF_CLIENT = 0x00000004,
PRF_ERASEBKGND = 0x00000008,
PRF_CHILDREN = 0x00000010;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, int lParam);
[DllImport("user32.dll")]
static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll")]
static extern bool EmptyClipboard();
[DllImport("user32.dll")]
static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);
[DllImport("user32.dll")]
static extern bool CloseClipboard();
[DllImport("gdi32.dll")]
static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc, IntPtr hNULL);
[DllImport("gdi32.dll")]
static extern bool DeleteEnhMetaFile(IntPtr hemf);
public static void DrawControl(Control control, Graphics g)
{
if (!control.Created)
control.CreateControl();
IntPtr hDc = g.GetHdc();
SendMessage(new HandleRef(control, control.Handle), WM_PRINT, (int)hDc,
(int)(PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT));
g.ReleaseHdc(hDc);
}
static public bool PutEnhMetafileOnClipboard(IntPtr hWnd, Metafile mf)
{
bool bResult = false;
IntPtr hEMF, hEMF2;
hEMF = mf.GetHenhmetafile(); // invalidates mf 
if (!hEMF.Equals(new IntPtr(0)))
{
hEMF2 = CopyEnhMetaFile(hEMF, new IntPtr(0));
if (!hEMF2.Equals(new IntPtr(0)))
{
if (OpenClipboard(hWnd))
{
if (EmptyClipboard())
{
IntPtr hRes = SetClipboardData(14 /*CF_ENHMETAFILE*/, hEMF2);
bResult = hRes.Equals(hEMF2);
CloseClipboard();
}
}
} DeleteEnhMetaFile(hEMF);
} return bResult;
}
private void CaptureScreen()
{
#region 矢量图
Graphics g1 = panelDraw.CreateGraphics();
IntPtr hdc = g1.GetHdc();
mf = new Metafile(hdc, new Rectangle(0, 0, panelDraw.Width, panelDraw.Height), MetafileFrameUnit.Pixel, EmfType.EmfOnly);
g1.ReleaseHdc(hdc);
g1.Dispose();
#endregion
}
#endregion private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
CaptureScreen();
DrawControl(panelDraw,e.Graphics);
  }使用以上代码可以打印输出panelDraw图形,但不是按定义new Rectangle(0, 0, panelDraw.Width, panelDraw.Height)打印输出的,结果比实际的要小,大约只有30%左右,是什么原因,能否给些建议!!!