/// <summary> /// Listen for mouse up event and proceed to upload. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); MakeClickable(); if (!isMouseDown) { return; } mouseUpPoint = mouseMovePoint = e.Location; mouseButtonUsed = e.Button; isMouseDown = false; // IMPORTANT: Convert the local (window) points to absolute (screen) points var region = CaptureService.GetRectangle( PointToScreen(mouseDownPoint), PointToScreen(mouseUpPoint)); if (region.Width < 1 || region.Height < 1) { return; } FormService.HideCropForms(); Application.DoEvents(); // Wait the form to be hidden Thread.Sleep(200); switch (e.Button) { case MouseButtons.Left: controller.CaptureImage(region); break; case MouseButtons.Right: controller.CaptureVideo(region); break; } }
/// <summary> /// Listen for mouse up event and proceed to upload. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); MakeClickable(); if (!isMouseDown) { return; } mouseUpPoint = mouseMovePoint = e.Location; mouseButtonUsed = e.Button; isMouseDown = false; var region = CaptureService.GetRectangle(mouseDownPoint, mouseUpPoint); if (region.X < 0 || region.Y < 0 || region.Width < 1 || region.Height < 1) { return; } FormService.HideCropForms(); Application.DoEvents(); SetScaling(); // Wait the crop form to be hidden Thread.Sleep(VersionService.GetPlatform() == PlatformType.Windows ? 50 : 500); switch (e.Button) { case MouseButtons.Left: controller.CaptureImage(region, screen.Location); break; case MouseButtons.Right: controller.CaptureVideo(region, screen.Location); break; } }
/// <summary> /// Paint the rectangle if the mouse button is down. /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!isMouseDown) { return; } var region = CaptureService.GetRectangle(mouseDownPoint, mouseMovePoint); if (mouseButtonUsed == MouseButtons.Left) { DrawSelectRectangle(e.Graphics, Config.LeftColor, region); } else if (mouseButtonUsed == MouseButtons.Right) { DrawSelectRectangle(e.Graphics, Config.RightColor, region); } lastRegion = region; }
/// <summary> /// Paint the rectangle if the mouse button is down. /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!isMouseDown) { return; } var draw = new Action <Brush, Rectangle>((color, r) => { if (!ConfigService.Current.NoTransparency) { var back = new SolidBrush(BackColor); if (last.X < r.X) { e.Graphics.FillRectangle(back, last.X, last.Y, r.X - last.X, last.Height); } if (last.Y < r.Y) { e.Graphics.FillRectangle(back, last.X, last.Y, last.Width, r.Y - last.Y); } if (last.Y + last.Height > r.Y + r.Height) { e.Graphics.FillRectangle(back, last.X, r.Y + r.Height, last.Width, last.Y + last.Height - (r.Y + r.Height)); } if (last.X + last.Width > r.X + r.Width) { e.Graphics.FillRectangle(back, r.X + r.Width, last.Y, last.X + last.Width - (r.X + r.Width), last.Height); } e.Graphics.FillRectangle(color, r.X, r.Y, r.Width, r.Height); } else { var path = new[] { new Point { X = r.X, Y = r.Y }, new Point { X = r.X + r.Width, Y = r.Y }, new Point { X = r.X + r.Width, Y = r.Y + r.Height }, new Point { X = r.X, Y = r.Y + r.Height }, new Point { X = r.X, Y = r.Y } }; e.Graphics.DrawLines(new Pen(color, Constants.PenWidth), path); } }); var rectangle = CaptureService.GetRectangle(mouseDownPoint, mouseMovePoint); switch (mouseButtonUsed) { case MouseButtons.Left: draw(Constants.LeftColor, rectangle); break; case MouseButtons.Right: draw(Constants.RightColor, rectangle); break; } last = rectangle; }