private Image CaptureWindow(CaptureMode mode) { Image img = null; IntPtr handle = IntPtr.Zero; Rectangle monitor = Rectangle.Empty; switch (mode) { case CaptureMode.FullScreen: handle = WindowNative.GetDesktopWindow(); if (CaptureSetting.FullScreenMode == FullScreenMode.MainMonitor) { monitor = Screen.PrimaryScreen.Bounds; } else if (CaptureSetting.FullScreenMode == FullScreenMode.ActiveMonitor) { monitor = Screen.GetBounds(Cursor.Position); } else if (CaptureSetting.FullScreenMode == FullScreenMode.AllMonitor) { monitor = SystemInformation.VirtualScreen; } img = CaptureWindow(handle, monitor.X, monitor.Y, monitor.Width, monitor.Height); break; case CaptureMode.ActiveProcess: handle = WindowNative.GetForegroundWindow(); img = CaptureWindow(handle, 0, 0, 0, 0); break; case CaptureMode.Region: handle = WindowNative.GetDesktopWindow(); monitor = SystemInformation.VirtualScreen; using (var tmp = CaptureWindow(handle, monitor.X, monitor.Y, monitor.Width, monitor.Height)) using (var dialog = new CaptureBackgroundDialog(tmp)) { dialog.TopMost = true; dialog.BringToFront(); if (dialog.ShowDialog() != DialogResult.OK) { return(null); } img = dialog.Image; } break; default: return(null); } return(img); }