調用Control
I
windows MetaFile 是windows 下面的一種矢量圖形格式
II
用GDI+繪圖的時候
首先我們來創建一個新的EMF文件
System
Graphics g
IntPtr hdc = g
mf = new Metafile(hdc
g
g
Graphics g
調用WinApi把控件打印到此Graphics 對象上面(這個Graphics對象會作為參數傳遞給下面一級一級的子控件的OnPaint()函數):
const int WM_PRINT =
const int PRF_CHECKVISIBLE =
PRF_NONCLIENT =
PRF_CLIENT =
PRF_ERASEBKGND =
PRF_CHILDREN =
[DllImport(
private static extern IntPtr SendMessage(HandleRef hWnd
public static void DrawControl(Control control
{
if (!control
control
IntPtr hDc = g
SendMessage(new HandleRef(control
(int)(PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT));
g
}
到這裡已經得到了這個控件的矢量圖了
[DllImport(
static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport(
static extern bool EmptyClipboard();
[DllImport(
static extern IntPtr SetClipboardData(uint uFormat
[DllImport(
static extern bool CloseClipboard();
[DllImport(
static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc
[DllImport(
static extern bool DeleteEnhMetaFile(IntPtr hemf);
static public bool PutEnhMetafileOnClipboard(IntPtr hWnd
{
bool bResult = false;
IntPtr hEMF
hEMF = mf
if (!hEMF
{
hEMF
if (!hEMF
{
if (OpenClipboard(hWnd))
{
if (EmptyClipboard())
{
IntPtr hRes = SetClipboardData(
bResult = hRes
CloseClipboard();
}
}
} DeleteEnhMetaFile(hEMF);
} return bResult;
}
運行這段代碼以後
From:http://tw.wingwit.com/Article/program/net/201311/13427.html