我正在使用以下代码来捕获Form
屏幕截图:
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.Activate();
Application.DoEvents();
Bitmap screenShotBMP = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
Graphics screenShotGraphics = Graphics.FromImage(screenShotBMP);
screenShotGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
screenShotBMP.Save(imagePath, ImageFormat.Gif);
screenShotGraphics.Dispose();
screenShotBMP.Dispose();
this.TopMost = false;
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Minimized;
当我登录到服务器时,它工作正常(我可以看到生成的屏幕截图)但是当它被锁定时,该行:
screenShotGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
给出错误“句柄无效”。
我才知道这是因为没有人登录时没有桌面。所以任何人都可以让我知道任何替代方案吗?
我有一个 WinForms 应用程序,计划每 5 分钟运行一次,当它运行时,我必须截取Form
.
请让我知道一个解决方案。