I'm trying to make repeated screenshots from one of my forms (i.e load the form with specific data, take and save the screenshot, then load the form with different data, take another screenshot, and so on).
The form contains overlapping Shape and Control elements. When I see the form on my screen, I get the proper z order, but on the screenshots, the z order is reversed.
I've already found some threads on the site explaining the reversed z order while using the DrawToBitmap method I'm currently using. I've also found the BringToFront() and SendToBack methods of Controls and Shapes, and tried to use them to adjust the z order to get proper screenshots. Still no success.
Then I read the documentation of the Shape class regarding these methods, and found the following remark:
The BringToFront method can be used to position a LineShape, OvalShape, or RectangleShape control in front of all other line and shape controls in a given container. It does not position the control in front of other types of controls in the container; graphics drawn by using line and shape controls always appear behind the other controls.
Is there a chance to change this behavior, and properly take a screenshot of my form using DrawToBitmap? Any idea for another solution? I've also tried the CopyFromScreen method of the Graphics class, but I want the whole screenshot-saving process to work without showing the forms I want to save.