0

This is a C# WinForms project where I have developed an app for drawing. The majority of the app has a transparent interface, allowing me to draw on the app/desktop underneath it. My goal is to incorporate a feature that enables me to save both the drawing and the app behind it as a jpg/png file. However, I'm facing an issue where taking a screenshot captures only a portion of the screen. I suspect this happens because I am using a laptop with two larger monitors, and I want the app to be compatible with any monitor configuration and size.

I tried:

Screen activeScreen = Screen.FromHandle(this.Handle);

            Bitmap screenshot = new Bitmap(activeScreen.Bounds.Width,
                activeScreen.Bounds.Height,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            using (Graphics gfxScreenshot = Graphics.FromImage(screenshot))
            {
                gfxScreenshot.CopyFromScreen(
                    activeScreen.Bounds.X,
                    activeScreen.Bounds.Y,
                    0,
                    0,
                    activeScreen.Bounds.Size,
                    CopyPixelOperation.SourceCopy);
            }

            using (SaveFileDialog saveDialog = new SaveFileDialog())
            {
                saveDialog.Filter = "PNG Image|*.png";
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    screenshot.Save(saveDialog.FileName, ImageFormat.Png);
                }
            }

and many more...

  • Could be useful: [Using SetWindowPos with multiple monitors](https://stackoverflow.com/a/53026765/7444103) -- Don't skip the notes about DpiAwareness -- You should specify what .NET version you're targeting – Jimi May 22 '23 at 14:17
  • [Take screenshot of multiple desktops of all visible applications and forms](https://stackoverflow.com/q/15847637) – 001 May 22 '23 at 14:18
  • Use CopyPixelOperation.CaptureBlt – Hans Passant May 22 '23 at 15:20
  • @Jimi : I'm using .NET Framework 4.7.2 – Nicocosaurus May 23 '23 at 11:51
  • After investigating the issue, I identified the reason why my code was not functioning correctly. It was due to the scaling of my monitors set to 125%. However, once I reverted the scaling back to 100%, the screenshots displayed normally. – Nicocosaurus May 23 '23 at 12:31
  • That's why you can see in the first comment: *Don't skip the notes about DpiAwareness* -> You have to make your App DpiAware, not change the scale of a Monitor. You cannot do that with an User machine, or otherwise force anyone to do it. It's your App that needs to adapt to whatever circumstances it finds – Jimi May 23 '23 at 13:15

0 Answers0