coolerfarmer

Untitled

Jun 26th, 2014
5,578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using Screenshot.Windows;
  6.  
  7. namespace Screenshot.Forms
  8. {
  9. /// <summary>
  10. /// Repre
  11. /// </summary>
  12. public sealed partial class SnippetDialog : Form
  13. {
  14. [Browsable(false)]
  15. public Rectangle SelectedArea { get; private set; }
  16. public Rectangle AbsoluteSelectedArea { get; private set; }
  17.  
  18. private Point _startLocation;
  19. private Point _startLocationAbsolut;
  20.  
  21. private bool _shouldDraw;
  22. private readonly Color _selectionColor = Color.FromArgb(50, 255, 99, 71);
  23.  
  24. public SnippetDialog()
  25. {
  26. InitializeComponent();
  27. Bounds = SystemInformation.VirtualScreen;
  28. BackgroundImage = ScreenshotProvider.TakeScreenshot(Bounds);
  29.  
  30. _startLocation = Cursor.Position;
  31. }
  32.  
  33. protected override void OnMouseDown(MouseEventArgs e)
  34. {
  35. // No need for code guard here
  36. if (e.Button == MouseButtons.Left)
  37. {
  38. _startLocation = e.Location;
  39. _shouldDraw = true;
  40. NativeMethods.POINT p;
  41. NativeMethods.GetCursorPos(out p);
  42. _startLocationAbsolut = new Point(p.X, p.Y);
  43. }
  44. }
  45.  
  46. protected override void OnMouseMove(MouseEventArgs e)
  47. {
  48. NativeMethods.POINT p;
  49. NativeMethods.GetCursorPos(out p);
  50.  
  51. SelectedArea = new Rectangle(
  52. Math.Min(_startLocation.X, e.X),
  53. Math.Min(_startLocation.Y, e.Y),
  54. Math.Abs(_startLocation.X - e.X),
  55. Math.Abs(_startLocation.Y - e.Y));
  56.  
  57. AbsoluteSelectedArea = new Rectangle(
  58. Math.Min(_startLocationAbsolut.X, p.X),
  59. Math.Min(_startLocationAbsolut.Y, p.Y),
  60. Math.Abs(_startLocationAbsolut.X - p.X),
  61. Math.Abs(_startLocationAbsolut.Y - p.Y));
  62.  
  63. if (_shouldDraw)
  64. {
  65. Invalidate();
  66. }
  67. }
  68.  
  69. protected override void OnPaint(PaintEventArgs e)
  70. {
  71. // 50 alpha so we can see behind it
  72. e.Graphics.FillRectangle(new SolidBrush(_selectionColor), SelectedArea);
  73. e.Graphics.DrawRectangle(Pens.Black, SelectedArea);
  74. }
  75.  
  76. protected override void OnMouseUp(MouseEventArgs e)
  77. {
  78. DialogResult = DialogResult.OK;
  79. }
  80.  
  81. protected override void OnKeyDown(KeyEventArgs e)
  82. {
  83. if (e.KeyCode == Keys.Escape)
  84. {
  85. DialogResult = DialogResult.Cancel;
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment