private Bitmap CaptureScreenshot()
{
try
{
Form formToCapture = null;
if (Application.OpenForms.Count > 0)
{
formToCapture = Application.OpenForms[0];
}
if (formToCapture != null)
{
Bitmap screenShot = new Bitmap(formToCapture.Width, formToCapture.Height);
Graphics g = Graphics.FromImage(screenShot);
g.CopyFromScreen(formToCapture.DesktopLocation, new Point(0, 0), screenShot.Size);
g.Dispose();
return screenShot;
}
}
catch (Exception)
{
// this error isn't important, we want to concentrate
// on the main exception instead
}
return null;
}