I've read tons of other questions and googled the issue, but I can only figure out how to do it if I'm using winforms. I'm currently writing a library, and one of the functions of the library is to handle logging. One of the features I'm implementing for it is to automatically take a screenshot of the page before writing the issue to the log. The issue with this is that I don't know which monitor to take a screenshot of, so if the user moves the browser to a different monitor, I still take a shot of the Primary one.
public static Bitmap ScreenShot(string saveLocation, string fileName)
{
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics.FromImage(bitmap).CopyFromScreen(0, 0, 0, 0, bitmap.Size);
string savePath = Path.Combine(Path.GetDirectoryName(saveLocation), "ScreenShots");
if (!Directory.Exists(savePath))
Directory.CreateDirectory(savePath);
bitmap.Save(Path.Combine(savePath, fileName), ImageFormat.Png);
return bitmap;
}
I've tried Screen.FromControl()
, but since it's not a winforms application, I don't have any System.Windows.Forms.Controls for it to find.
Does ASP.NET have any equivalent? Or something I can explicitly cast to a winform control?