在vs2003中,可以通过MSChart.EditCopy()方法,再从简帖板(ClipBoard)获得已经绘制的图片,然后再进行保存图片或者打印操作。
public class Win32
{
[System.Runtime.InteropServices.DllImport("gdi32", EntryPoint = "BitBlt")]
public static extern int BitBlt (int hDestDC, int x, int y, int nWidth, int nHeight, int hSrcDC, int xSrc, int ySrc, int dwRop);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "GetWindowDC")]
public static extern int GetWindowDC(int hwnd);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "ReleaseDC")]
public static extern int ReleaseDC(int hwnd, int hdc);
public const int SRCCOPY = 13369376;
}
借用这个辅助类生成控件的图形:
/// <summary>
/// 绘制整个控件位BitMap
/// </summary>
/// <param name="Control">要绘制的控件</param>
/// <returns></returns>
public static Bitmap CreateBitmap(Control Control)
{
Graphics gDest;
IntPtr hdcDest;
int hdcSrc;
int hWnd = Control.Handle.ToInt32();
Bitmap BmpDrawed = new Bitmap(Control.Width, Control.Height);
gDest = Graphics.FromImage(BmpDrawed);
hdcSrc = Win32.GetWindowDC(hWnd);
hdcDest = gDest.GetHdc();
Win32.BitBlt(hdcDest.ToInt32(), 0, 0, Control.Width, Control.Height, hdcSrc, 0, 0, Win32.SRCCOPY);
gDest.ReleaseHdc(hdcDest);
Win32.ReleaseDC(hWnd, hdcSrc);
return BmpDrawed;
}
需要增加一个辅助类: