Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- using Screenshot.Windows;
- namespace Screenshot.Forms
- {
- /// <summary>
- /// Repre
- /// </summary>
- public sealed partial class SnippetDialog : Form
- {
- [Browsable(false)]
- public Rectangle SelectedArea { get; private set; }
- public Rectangle AbsoluteSelectedArea { get; private set; }
- private Point _startLocation;
- private Point _startLocationAbsolut;
- private bool _shouldDraw;
- private readonly Color _selectionColor = Color.FromArgb(50, 255, 99, 71);
- public SnippetDialog()
- {
- InitializeComponent();
- Bounds = SystemInformation.VirtualScreen;
- BackgroundImage = ScreenshotProvider.TakeScreenshot(Bounds);
- _startLocation = Cursor.Position;
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- // No need for code guard here
- if (e.Button == MouseButtons.Left)
- {
- _startLocation = e.Location;
- _shouldDraw = true;
- NativeMethods.POINT p;
- NativeMethods.GetCursorPos(out p);
- _startLocationAbsolut = new Point(p.X, p.Y);
- }
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- NativeMethods.POINT p;
- NativeMethods.GetCursorPos(out p);
- SelectedArea = new Rectangle(
- Math.Min(_startLocation.X, e.X),
- Math.Min(_startLocation.Y, e.Y),
- Math.Abs(_startLocation.X - e.X),
- Math.Abs(_startLocation.Y - e.Y));
- AbsoluteSelectedArea = new Rectangle(
- Math.Min(_startLocationAbsolut.X, p.X),
- Math.Min(_startLocationAbsolut.Y, p.Y),
- Math.Abs(_startLocationAbsolut.X - p.X),
- Math.Abs(_startLocationAbsolut.Y - p.Y));
- if (_shouldDraw)
- {
- Invalidate();
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- // 50 alpha so we can see behind it
- e.Graphics.FillRectangle(new SolidBrush(_selectionColor), SelectedArea);
- e.Graphics.DrawRectangle(Pens.Black, SelectedArea);
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- DialogResult = DialogResult.OK;
- }
- protected override void OnKeyDown(KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Escape)
- {
- DialogResult = DialogResult.Cancel;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment