WinForm Specifies a screenshot of the control area (such as intercepting a panel area in a form)

Source: Internet
Author: User

    <summary>///auxiliary class definition GDI32 API function///</summary> public class GDI32 {public Co        NST 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>///auxiliary class definition User32 API function///</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); Call: (can be passed to control handle) public Image CaptureWindow (IntPtr handle) {IntPtr hdcsrc = USER32.GETWINDOWDC (han            DLE);            User32.rect windowrect = new User32.rect ();            User32.getwindowrect (handle, ref windowrect);            int width = Windowrect.right-windowrect.left;            int height = windowrect.bottom-windowrect.top; IntPtr hdcdest = GDI32. CreateCompatibledc (HDCSRC); IntPtr hbitmap = GDI32.            CreateCompatibleBitmap (hdcsrc, width, height); IntPtr hold = GDI32.            SelectObject (Hdcdest, HBITMAP); GDI32. BitBlt (hdcdest, 0, 0, width, height, hdcsrc, 0, 0, GDI32.            SRCCOPY); GDI32.            SelectObject (Hdcdest, hold); GDI32.            DeleteDC (hdcdest);            USER32.RELEASEDC (handle, HDCSRC);            Image img = image.fromhbitmap (HBITMAP); GDI32.            DeleteObject (HBITMAP);        return img; }

  

WinForm Specifies the control area (for example, a panel area in the interception form)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.