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...