I have a C# application Winforms .Net 3.5
that takes a screenshot of itself. When running under Windows 7
, it works fine, but under Windows 10
, the screenshot is offset from the window. With 100% magnification, the screenshot is just a little larger than the window, showing a few pixels of the background on the sides and bottom. But for larger magnifications, it shows a frame that is offset to the upper left by an amount that increases with the magnification level. Since this application needs to be run on laptops where the magnification is necessary (particularly for those of us with old eyes), this is a significant issue.
The code taking the screenshot is
Rectangle bounds = this.Bounds;
using (Bitmap ScreenShot = new Bitmap(bounds.Width, bounds.Height))
{
// code hiding a few controls on the form (control.Visible = false)
this.Update();
using (Graphics G = Graphics.FromImage(ScreenShot))
{
G.CopyFromScreen(bounds.Left, bounds.Top, 0, 0, bounds.Size);
}
// code unhiding the same elements
SaveScreenshot(Screenshot);
}
The application was originally compiled under Windows 7 using VS2008
, but recompiling it under Windows 10
with VS2017
hasn't solved the issue.
Any ideas what would cause this to go wrong under Windows 10
, but not Windows 7
?
I would prefer not to have to upgrade to a later version of .Net
if possible.
Here is a sample of the screenshots it is providing at 125% magnification.