首页 > 代码库 > winform 指定控件区域截图(比如截取窗体中的某个Panel区域)

winform 指定控件区域截图(比如截取窗体中的某个Panel区域)

    /// <summary>      /// 辅助类 定义Gdi32 API函数      /// </summary>      public class GDI32    {        public const int SRCCOPY = 0x00CC0020;        [DllImport("gdi32.dll")]        public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth,                        int nHeight, IntPtr hObjectSource, int nXSrc, int nYSrc, int dwRop);        [DllImport("gdi32.dll")]        public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight);        [DllImport("gdi32.dll")]        public static extern IntPtr CreateCompatibleDC(IntPtr hDC);        [DllImport("gdi32.dll")]        public static extern bool DeleteDC(IntPtr hDC);        [DllImport("gdi32.dll")]        public static extern bool DeleteObject(IntPtr hObject);        [DllImport("gdi32.dll")]        public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);    }    /// <summary>      /// 辅助类 定义User32 API函数      /// </summary>      public class User32    {        [StructLayout(LayoutKind.Sequential)]        public struct RECT        {            public int left;            public int top;            public int right;            public int bottom;        }        [DllImport("user32.dll")]        public static extern IntPtr GetDesktopWindow();        [DllImport("user32.dll")]        public static extern IntPtr GetWindowDC(IntPtr hWnd);        [DllImport("user32.dll")]        public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);        [DllImport("user32.dll")]        public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);    }调用:(传入控件句柄即可)        public Image CaptureWindow(IntPtr handle)        {            IntPtr hdcSrc = http://www.mamicode.com/User32.GetWindowDC(handle);>

  

winform 指定控件区域截图(比如截取窗体中的某个Panel区域)