But on computer 2 interception is not normal, because he will take the front panel of the contained in that block control computers are W7, configuration is the same, don't know if the computer problem set or other causes,
[DllImport (" gdi32. DLL)]
Private static extern bool BitBlt (IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);
[DllImport (" user32. DLL)]
Public static extern IntPtr GetWindowDC IntPtr (PTR);
[DllImport (" user32. DLL)]
Private static extern bool ReleaseDC (IntPtr hWnd, IntPtr hDc);
[DllImport (" gdi32. DLL)]
Private static extern IntPtr SelectObject (IntPtr HDC, IntPtr BMP);
[DllImport (" gdi32. DLL)]
Private static extern IntPtr CreateCompatibleBitmap (IntPtr HDC, int nWidth, int nHeight);
[DllImport (" gdi32. DLL)]
Private static extern IntPtr CreateCompatibleDC (IntPtr HDC);
[DllImport (" gdi32. DLL)]
Private static extern IntPtr DeleteDC IntPtr (hDc);
[DllImport (" gdi32. DLL)]
Private static extern IntPtr DeleteObject IntPtr (hDc);
Public Bitmap captureControl Control (Control)
{
Try
{
IntPtr windowDC=GetWindowDC (control. Handle);
IntPtr HDC=CreateCompatibleDC (windowDC);
IntPtr BMP=CreateCompatibleBitmap (windowDC, control the Width and the control, Height);
IntPtr ptr4=SelectObject (HDC, BMP);
If (BitBlt (HDC, 0, 0, control the Width and the control. The Height, windowDC, 0, 0, CopyPixelOperation. CaptureBlt | CopyPixelOperation. SourceCopy))
{
Bitmap Bitmap=Image. FromHbitmap (BMP);
SelectObject (HDC, ptr4);
DeleteObject (BMP);
DeleteDC (HDC);
ReleaseDC (control Handle, windowDC);
Return the bitmap;
}
return null;
}
The catch (Exception)
{
return null;
}
}
Private void button5_Click (object sender, EventArgs e)
{
This. Panel1. Refresh ();
Bitmap Bitmap=captureControl (enclosing panel1);
The string filename=@ "D: \ 6. PNG";
Bitmap. The Save (filename, ImageFormat. Jpeg);
}
CodePudding user response:
Screenshots can put controls in front to rear bai, cut out put in front of,CodePudding user response: