I am trying to bring my Form to the top, take screenshot, save it and then minimize it back using the following code.
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
Application.DoEvents();
string keys = "%" + "{PrtSc}";
SendKeys.SendWait(keys);
Clipboard.GetImage().Save(imagePath, ImageFormat.Jpeg);
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Minimized;
this.TopMost = false;
I thought the code will always bring the window on top and take the screenshot. However I noticed that its not 100% working: The machine is too slow, so when the code that bring the window to top executes, the entire window does not appear. Sometimes It does not bring it to top, so the pic contains some user activity.
How can I bring it completely to the top and wait till its done complete and then take a screenshot and reverse it.
Please note that there is a single form in the application.