以下代码在“窗体表单应用程序”中捕获桌面的屏幕截图
但是为什么这段代码无法捕获“Window Service Application”中的截图
protected override void OnStart(string[] args)
{
aTimer = new System.Timers.Timer(5000);
aTimer.Elapsed += new ElapsedEventHandler(CaptureScreen);
aTimer.Enabled = true;
}
public void CaptureScreen(object sender, EventArgs e)
{
bmp = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
gr = Graphics.FromImage(bmp);
gr.CopyFromScreen(0, 0, 0, 0, new Size(bmp.Size.Width, bmp.Size.Height));
bmp.Save("D://screenshot.jpg");
}