我正在寫一個簡單的Windows窗體實用程序來截屏整個屏幕或活動窗口並保存文件。該winform有一個名爲'Capture'的按鈕,點擊後會截取屏幕截圖。PrintScreen only active window
我的代碼完全適用於整個屏幕,但無法找出活動窗口。
通過我當前的代碼,如果我選擇「活動窗口」,它會結束Print Screening應用程序本身,這不是我想要的。
這裏是我的代碼(Capture_Click方法下):
try
{
this.Hide();
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
//bmpScreenshot = new Bitmap(this.Bounds.Width, this.Bounds.Height, PixelFormat.Format32bppArgb);
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
if (AltPrint.Checked)
{
gfxScreenshot.CopyFromScreen(this.Bounds.X, this.Bounds.Y, 0, 0, this.Bounds.Size, CopyPixelOperation.SourceCopy);
}
else
{
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
}
bmpScreenshot.Save(SaveLocation, ImageFormat.Png);
number++;
}
你重建`PrintScreen`和'ALT + PrintScreen` *按鍵*? – 2011-01-14 15:13:09
「select active window」是什麼意思?你如何選擇它? – Nobody 2011-01-14 15:14:35
@奧斯汀:不,我的winform有一個名爲Capture的按鈕。點擊它,截圖。上面粘貼的代碼位於button_Click方法中。 – xbonez 2011-01-14 15:18:44