public static Rectangle Snip(Rectangle bound) { if (bound.IsEmpty) { throw new ArgumentException("bound.IsEmpty"); } Rectangle outputRegion = Rectangle.Empty; var bmp = new Bitmap(bound.Width, bound.Height, PixelFormat.Format32bppPArgb); try { using (var g = Graphics.FromImage(bmp)) { g.CopyFromScreen(bound.X, bound.Y, 0, 0, bmp.Size);//, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt); } var form = new SnippingForm() { BackgroundImage = bmp, Bounds = bound, }; try { //form.MouseUp += (o, a) => //{ // form.Close(); //}; form.ShowDialog(); var srcRect = form.SourceRectangle; var screenRect = form.ScreenRectangle; int left = srcRect.Left + screenRect.Left; int top = srcRect.Top + screenRect.Top; outputRegion = new Rectangle(left, top, srcRect.Width, srcRect.Height); } finally { form?.Dispose(); } } catch (Exception ex) { Debug.Fail(ex.Message); Trace.WriteLine(ex); } finally { bmp?.Dispose(); } return(outputRegion); }
public void OnNKey() { if (!VerifyFileNameNotEmpty()) { return; } inProgress = true; var snippingForm = new SnippingForm(); if (snippingForm.ShowDialog() == DialogResult.OK) { OnKeyCommon(snippingForm.CaptureFromSnip); } inProgress = false; }