I found here an excellent solution for creating screenshots on the window descriptor. I edited it a little to fit my needs, the following happened:

using (var image = new Bitmap(rect.Right - rect.Left, rect.Bottom - rect.Top)) { using (var graphics = Graphics.FromImage(image)) { var hdcBitmap = graphics.GetHdc(); WinAPI.PrintWindow(Handle, hdcBitmap, 0); graphics.ReleaseHdc(hdcBitmap); } bmp = new Bitmap(image); } 

WinAPI is just a wrapper class of extern functions. But, if I'm not mistaken, the controls are also windows and have their own Handle. This method cannot take a snapshot of the control. Yes, I know about DrawToBitmap, but how to rewrite this method so that it works in both cases, because absolutely any window descriptor can be passed.

  • You need to use this - Vasek
  • But then I will get the form itself. Well, if it were possible to determine what I am dealing with - by form or control. In the case of a control, I would simply cut out the Rectangle control from the screenshot, but I do not see a universal solution. Although ... you can always cut out the necessary control from the screenshot of the parent, the form will also work, but you will not be able to take a screenshot from the desktop. And with GetDesktopWindow, I never managed to work. - Uranus
  • Sorry did not immediately understand the essence of the question. To determine that the handle is a child, there is a function IsChild . You basically reason correctly. You just need to write a function that will make a screen of the entire parent window and cut a rectangle out of it. A rectangle will be either a child control or the entire area of ​​the main window. IMHO is a fairly universal solution. - Vasek
  • Thanks, I will try, and I will unsubscribe after the fact! - Uranus

0