Picturebox.xaml.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace AIRS
  16. {
  17. /// <summary>
  18. /// Picturebox.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class Picturebox : UserControl
  21. {
  22. public Boolean st = false;
  23. private Boolean ismove = false;
  24. private Boolean isDown = false;
  25. Point ptDown = new Point();
  26. public String cir_rect = "";
  27. public double zoom_key = 1;
  28. public double rect_left = 0;
  29. public double rect_top = 0;
  30. public double _PixelWidth = 0;
  31. public double _PixelHeight = 0;
  32. public Boolean Frozen = false;
  33. public string grade_value = "";
  34. public Picturebox()
  35. {
  36. InitializeComponent();
  37. }
  38. private void btnanalysis_MouseMove(object sender, MouseEventArgs e)
  39. {
  40. if (!ismove)
  41. {
  42. btnanalysis.Width = btnanalysis.Width + 2;
  43. btnanalysis.Height = btnanalysis.Height + 2;
  44. btnanalysis.FontSize = 14;
  45. ismove = !ismove;
  46. }
  47. }
  48. private void btnanalysis_MouseLeave(object sender, MouseEventArgs e)
  49. {
  50. btnanalysis.Width = btnanalysis.Width - 2;
  51. btnanalysis.Height = btnanalysis.Height - 2;
  52. btnanalysis.FontSize = 13;
  53. ismove = false;
  54. }
  55. private void cantest_MouseDown(object sender, MouseButtonEventArgs e)
  56. {
  57. if(Frozen==true)
  58. {
  59. return;
  60. }
  61. ptDown = e.GetPosition((IInputElement)sender);
  62. if(cir_rect=="Circle")
  63. {
  64. double liner = Math.Pow(ptDown.X - circle.Center.X, 2.0) + Math.Pow(ptDown.Y - circle.Center.Y, 2.0);
  65. if(liner>Math.Pow(circle.RadiusX,2.0))
  66. {
  67. return;
  68. }
  69. this.Cursor = System.Windows.Input.Cursors.Hand;
  70. isDown = true;
  71. }
  72. else if(cir_rect=="Rectangle")
  73. {
  74. if(ptDown.X<rectrr.Rect.X || ptDown.X>(rectrr.Rect.X+rectrr.Rect.Width) ||
  75. ptDown.Y < rectrr.Rect.Y || ptDown.Y > (rectrr.Rect.Y + rectrr.Rect.Height))
  76. {
  77. return;
  78. }
  79. this.Cursor = System.Windows.Input.Cursors.Hand;
  80. isDown = true;
  81. }
  82. }
  83. private void cantest_MouseMove(object sender, MouseEventArgs e)
  84. {
  85. if (isDown)
  86. {
  87. if (cir_rect == "Circle")
  88. {
  89. this.Cursor = System.Windows.Input.Cursors.ScrollAll;
  90. Point pt = e.GetPosition((IInputElement)sender);
  91. double x = pt.X - ptDown.X;
  92. double y = pt.Y - ptDown.Y;
  93. Point ptm = circle.Center;
  94. ptm.X = ptm.X + x;
  95. ptm.Y = ptm.Y + y;
  96. ptDown = new Point(ptDown.X + x, ptDown.Y + y);
  97. circle.Center = new Point(circle.Center.X + x, circle.Center.Y + y);
  98. //判断圆是否出图像
  99. if ((circle.Center.X-circle.RadiusX) < rect_left)
  100. {
  101. circle.Center = new Point(circle.RadiusX + rect_left, circle.Center.Y);
  102. }
  103. if((circle.Center.Y - circle.RadiusY) < rect_top)
  104. {
  105. circle.Center = new Point(circle.Center.X, circle.RadiusY + rect_top);
  106. }
  107. if((circle.Center.X+circle.RadiusX)>(img.Width-rect_left))
  108. {
  109. circle.Center = new Point(img.Width - rect_left - circle.RadiusX, circle.Center.Y);
  110. }
  111. if ((circle.Center.Y + circle.RadiusY) > (img.Height - rect_top))
  112. {
  113. circle.Center = new Point(circle.Center.X, img.Height - rect_top - circle.RadiusY);
  114. }
  115. }
  116. else if (cir_rect == "Rectangle")
  117. {
  118. this.Cursor = System.Windows.Input.Cursors.ScrollAll;
  119. Point pt = e.GetPosition((IInputElement)sender);
  120. double x = pt.X - ptDown.X;
  121. double y = pt.Y - ptDown.Y;
  122. Rect rtm = rectrr.Rect;
  123. rtm.X = rtm.X + x;
  124. rtm.Y = rtm.Y + y;
  125. ptDown = new Point(ptDown.X + x, ptDown.Y + y);
  126. rectrr.Rect = rtm;
  127. if(rectrr.Rect.X<rect_left)
  128. {
  129. rtm.X = rect_left;
  130. rectrr.Rect = rtm;
  131. }
  132. if (rectrr.Rect.Y < rect_top)
  133. {
  134. rtm.Y = rect_top;
  135. rectrr.Rect = rtm;
  136. }
  137. if ((rectrr.Rect.X + rectrr.Rect.Width) > (img.Width- rect_left))
  138. {
  139. rtm.X = img.Width - rect_left - rectrr.Rect.Width;
  140. rectrr.Rect = rtm;
  141. }
  142. if ((rectrr.Rect.Y + rectrr.Rect.Height) > (img.Height - rect_top))
  143. {
  144. rtm.Y = img.Height - rect_top - rectrr.Rect.Height;
  145. rectrr.Rect = rtm;
  146. }
  147. }
  148. }
  149. }
  150. private void cantest_MouseUp(object sender, MouseButtonEventArgs e)
  151. {
  152. if (isDown)
  153. {
  154. isDown = false;
  155. this.Cursor = System.Windows.Input.Cursors.Arrow;
  156. }
  157. }
  158. private void cantest_MouseLeave(object sender, MouseEventArgs e)
  159. {
  160. if (isDown)
  161. {
  162. isDown = false;
  163. this.Cursor = System.Windows.Input.Cursors.Arrow;
  164. }
  165. }
  166. }
  167. }