Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. public struct Area
  2. {
  3. public int minX;
  4. public int minY;
  5. public int maxX;
  6. public int maxY;
  7. public bool xForward;
  8. public bool yForward;
  9. public bool Lock;
  10. }
  11.  
  12. Area Selection;
  13.  
  14. private void PictureBox6_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  15. {
  16. switch (e.Button) {
  17. case System.Windows.Forms.MouseButtons.Left:
  18. var _with1 = Selection;
  19. _with1.xForward = true;
  20. _with1.yForward = true;
  21. _with1.minX = e.Location.X;
  22. _with1.minY = e.Location.Y;
  23. _with1.Lock = true;
  24. if (CheckBox8.Checked == false) {
  25. PictureBox6.Image = My.Resources.Map;
  26. }
  27. break;
  28. }
  29. }
  30.  
  31. private void PictureBox6_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  32. {
  33. if (Selection.Lock == true) {
  34. var _with2 = Selection;
  35. if (e.Location.X < 0) {
  36. _with2.minX = 0;
  37. } else if (e.Location.Y < 0) {
  38. _with2.minY = 0;
  39. } else if (PictureBox6.Width < e.Location.X) {
  40. _with2.maxX = PictureBox6.Width - 1;
  41. if (PictureBox6.Height > e.Location.Y) {
  42. if (e.Location.Y > _with2.minY) {
  43. if (_with2.yForward == true) {
  44. _with2.maxY = e.Location.Y;
  45. } else {
  46. if (e.Location.Y < _with2.maxY) {
  47. _with2.minY = e.Location.Y;
  48. } else {
  49. _with2.minY = _with2.maxY;
  50. _with2.maxY = e.Location.Y;
  51. _with2.yForward = true;
  52. }
  53. }
  54. } else {
  55. if (_with2.yForward == true) {
  56. _with2.maxY = _with2.minY;
  57. _with2.minY = e.Location.Y;
  58. _with2.yForward = false;
  59. } else {
  60. if (_with2.minY <= _with2.maxY) {
  61. _with2.minY = e.Location.Y;
  62. } else {
  63. _with2.maxY = e.Location.Y;
  64. }
  65. }
  66. }
  67. }
  68. } else if (PictureBox6.Height < e.Location.Y) {
  69. _with2.maxY = PictureBox6.Height - 1;
  70. if (PictureBox6.Width > e.Location.X) {
  71. if (e.Location.X > _with2.minX) {
  72. if (_with2.xForward == true) {
  73. _with2.maxX = e.Location.X;
  74. } else {
  75. if (e.Location.X < _with2.maxX) {
  76. _with2.minX = e.Location.X;
  77. } else {
  78. _with2.minX = _with2.maxX;
  79. _with2.maxX = e.Location.X;
  80. _with2.xForward = true;
  81. }
  82. }
  83. } else {
  84. if (_with2.xForward == true) {
  85. _with2.maxX = _with2.minX;
  86. _with2.minX = e.Location.X;
  87. _with2.xForward = false;
  88. } else {
  89. if (_with2.minX <= _with2.maxX) {
  90. _with2.minX = e.Location.X;
  91. } else {
  92. _with2.maxX = e.Location.X;
  93. }
  94. }
  95. }
  96. }
  97. } else {
  98. if (e.Location.X > _with2.minX) {
  99. if (_with2.xForward == true) {
  100. _with2.maxX = e.Location.X;
  101. } else {
  102. if (e.Location.X < _with2.maxX) {
  103. _with2.minX = e.Location.X;
  104. } else {
  105. _with2.minX = _with2.maxX;
  106. _with2.maxX = e.Location.X;
  107. _with2.xForward = true;
  108. }
  109. }
  110. } else {
  111. if (_with2.xForward == true) {
  112. _with2.maxX = _with2.minX;
  113. _with2.minX = e.Location.X;
  114. _with2.xForward = false;
  115. } else {
  116. if (_with2.minX <= _with2.maxX) {
  117. _with2.minX = e.Location.X;
  118. } else {
  119. _with2.maxX = e.Location.X;
  120. }
  121. }
  122. }
  123. if (e.Location.Y > _with2.minY) {
  124. if (_with2.yForward == true) {
  125. _with2.maxY = e.Location.Y;
  126. } else {
  127. if (e.Location.Y < _with2.maxY) {
  128. _with2.minY = e.Location.Y;
  129. } else {
  130. _with2.minY = _with2.maxY;
  131. _with2.maxY = e.Location.Y;
  132. _with2.yForward = true;
  133. }
  134. }
  135. } else {
  136. if (_with2.yForward == true) {
  137. _with2.maxY = _with2.minY;
  138. _with2.minY = e.Location.Y;
  139. _with2.yForward = false;
  140. } else {
  141. if (_with2.minY <= _with2.maxY) {
  142. _with2.minY = e.Location.Y;
  143. } else {
  144. _with2.maxY = e.Location.Y;
  145. }
  146. }
  147. }
  148. }
  149. PictureBox1.Refresh();
  150. PictureBox1.CreateGraphics.FillRectangle(new SolidBrush(Color.FromArgb(128, 255, 0, 0)), new Rectangle(_with2.minX, _with2.minY, _with2.maxX - _with2.minX, _with2.maxY - _with2.minY));
  151. PictureBox1.CreateGraphics.Dispose();
  152. }
  153. }
  154.  
  155. private void PictureBox6_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  156. {
  157. if (Selection.Lock == true) {
  158. //Here you move the image
  159. Selection.Lock = false;
  160. }
  161. }
Add Comment
Please, Sign In to add comment