/// <summary> /// Intercept the key down event, to snag some images /// </summary> /// <param name="e"></param> protected override void OnKeyDown(KeyEventArgs e) { CaptureActions action = CaptureActions.None; switch (e.KeyCode) { case CaptureActionKeyDesktop: action = CaptureActions.Desktop; break; case CaptureActionKeyWindow: action = CaptureActions.Window; break; case CaptureActionKeyWindowSmallIcon: action = CaptureActions.SmallIcon; break; case CaptureActionKeyWindowLargeIcon: action = CaptureActions.LargeIcon; break; case CaptureActionKeyClear: action = CaptureActions.Clear; break; } ; base.OnKeyDown(e); if (action != CaptureActions.None) { this.PerformAction(action); } }
/// <summary> /// Performs the specified type of capture action and displays the image /// </summary> /// <param name="action">The action to perform</param> private void PerformAction(CaptureActions action) { Image image = null; switch (action) { case CaptureActions.Desktop: image = (Image)ScreenCapturing.GetDesktopWindowCaptureAsBitmap(); break; case CaptureActions.Window: image = (Image)ScreenCapturing.GetWindowCaptureAsBitmap((int)this.Handle); break; case CaptureActions.SmallIcon: image = (Image)ScreenCapturing.GetWindowSmallIconAsBitmap((int)this.Handle); break; case CaptureActions.LargeIcon: image = (Image)ScreenCapturing.GetWindowLargeIconAsBitmap((int)this.Handle); break; default: // if it's clear we'll just display a null image break; } ; this.DisplayImage(image, true, PictureBoxSizeMode.Normal /* doesn't matter as audo decide sizing is enabled */); }
/// <summary> /// Performs the specified type of capture action and displays the image /// </summary> /// <param name="action">The action to perform</param> private void PerformAction(CaptureActions action) { Image image = null; switch(action) { case CaptureActions.Desktop: image = (Image)ScreenCapturing.GetDesktopWindowCaptureAsBitmap(); break; case CaptureActions.Window: image = (Image)ScreenCapturing.GetWindowCaptureAsBitmap((int)this.Handle); break; case CaptureActions.SmallIcon: image = (Image)ScreenCapturing.GetWindowSmallIconAsBitmap((int)this.Handle); break; case CaptureActions.LargeIcon: image = (Image)ScreenCapturing.GetWindowLargeIconAsBitmap((int)this.Handle); break; default: // if it's clear we'll just display a null image break; }; this.DisplayImage(image, true, PictureBoxSizeMode.Normal /* doesn't matter as audo decide sizing is enabled */); }