ToolWorkType.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. using PaintDotNet.Annotation.Enum;
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet.Annotation.Label
  6. {
  7. /// <summary>
  8. /// 标注->工字线
  9. /// </summary>
  10. public class ToolWorkType : ToolObject
  11. {
  12. private static DrawWorkType newWorkType;
  13. /// <summary>
  14. /// 辅助计算点击次数
  15. /// </summary>
  16. private static int clickCount = 0;
  17. /// <summary>
  18. /// 数值输入
  19. /// </summary>
  20. //private static NumericUpDown lab;
  21. private static LabelUsedDialog labelUsedDialog;
  22. private static ISurfaceBox areaNow;
  23. private static Cursor cursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationPolyHandle.cur"));
  24. public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e)
  25. {
  26. areaNow = drawArea;
  27. if (e.Button == MouseButtons.Left)
  28. {
  29. clickCount += 1;
  30. Point p = GetEventPointInArea(drawArea, e.Location);
  31. if (clickCount == 1)
  32. {
  33. if (newWorkType == null)
  34. {
  35. newWorkType = new DrawWorkType(drawArea, p.X, p.Y);
  36. newWorkType.ISurfaceBox = drawArea;
  37. AddNewObject(drawArea, newWorkType);
  38. }
  39. }
  40. if (clickCount == 2)
  41. {
  42. Point temp = drawArea.GetCalcOriginPoint();
  43. }
  44. if (clickCount == 3)
  45. {
  46. newWorkType.judgeP = GetEventPointInArea(drawArea, e.Location);
  47. labelUsedDialog = new LabelUsedDialog();
  48. labelUsedDialog.Text = "工字线距离";
  49. labelUsedDialog.textBox1.Text = newWorkType.labelWorkTypeStyleMode.distance.ToString();
  50. labelUsedDialog.button1.Click += new EventHandler(LabelUsedDialogButton1_Click);
  51. labelUsedDialog.button2.Click += new EventHandler(LabelUsedDialogButton2_Click);
  52. labelUsedDialog.textBox1.KeyPress += new KeyPressEventHandler(TextBox1_KeyPress);
  53. labelUsedDialog.StartPosition = FormStartPosition.CenterParent;
  54. labelUsedDialog.ShowDialog();
  55. //lab = new NumericUpDown();
  56. //lab.Cursor = Cursors.Default;
  57. //lab.LostFocus += new EventHandler(OnNumbericLostFocus);
  58. ////lab.Location = new Point(p.X + temp.X ,p.Y + temp.Y);
  59. ////lab.Location = new Point(e.X, e.Y);
  60. //lab.Location = new Point(temp.X + (int)(p.X * drawArea.ScaleRatio) + 16, temp.Y + (int)(p.Y * drawArea.ScaleRatio) + 16);
  61. //lab.Maximum = 9999;
  62. //lab.Minimum = 0;
  63. //lab.DecimalPlaces = 2;
  64. //lab.Increment = 0.5M;
  65. //lab.Value = 10;
  66. //drawArea.Controls.Add(lab);
  67. //lab.Focus();
  68. //lab.BringToFront();
  69. //drawArea.Refresh();
  70. }
  71. //if (clickCount == 3)
  72. //{
  73. // newWorkType.textboxMessage = lab.Text;
  74. // drawArea.Controls.Remove(lab);
  75. // drawArea.Refresh();
  76. // clickCount = 0;
  77. // newWorkType = null;
  78. // if (!drawArea.ContinuousDrawingLabel())
  79. // {
  80. // OnMouseUpTwo(drawArea, e);
  81. // }
  82. //}
  83. }
  84. else {
  85. OnMouseNotLeftDown(drawArea, null);
  86. }
  87. }
  88. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  89. {
  90. if (newWorkType != null && clickCount == 1)
  91. {
  92. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  93. if (newWorkType.pointArray.Count == 1)
  94. newWorkType.setNextPoint(pointscroll);
  95. else
  96. newWorkType.pointArray[1] = pointscroll;
  97. drawArea.Refresh();
  98. drawArea.GraphicsList.Dirty = true;
  99. }
  100. }
  101. private static void LabelUsedDialogButton1_Click(object sender, EventArgs e)
  102. {
  103. if (string.IsNullOrEmpty(labelUsedDialog.textBox1.Text))
  104. {
  105. MessageBox.Show("距离值不能为空,请重新输入");
  106. return;
  107. }
  108. else
  109. {
  110. newWorkType.textboxMessage = labelUsedDialog.textBox1.Text;
  111. areaNow.Refresh();
  112. clickCount = 0;
  113. newWorkType = null;
  114. if (!areaNow.ContinuousDrawingLabel())
  115. {
  116. areaNow.ActiveTool = DrawToolType.Pointer;
  117. }
  118. OnMouseUpTwo(areaNow, null);
  119. labelUsedDialog.Close();
  120. }
  121. }
  122. private static void LabelUsedDialogButton2_Click(object sender, EventArgs e)
  123. {
  124. if(newWorkType != null && areaNow != null)
  125. {
  126. RemoveOldObject(areaNow, newWorkType);
  127. areaNow.Refresh();
  128. areaNow.RefreshLabelListDialog();
  129. clickCount = 0;
  130. newWorkType = null;
  131. if (!areaNow.ContinuousDrawingLabel())
  132. {
  133. OnMouseUpTwo(areaNow, null);
  134. }
  135. }
  136. }
  137. private static void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
  138. {
  139. TextBox textBox1 = (TextBox)sender;
  140. //判断按键是不是要输入的类型
  141. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  142. e.Handled = true;
  143. //小数点的处理
  144. if ((int)e.KeyChar == 46)//小数点
  145. {
  146. if (textBox1.Text.Length <= 0)
  147. e.Handled = true; //小数点不能在第一位
  148. else
  149. {
  150. float f;
  151. float oldf;
  152. bool b1 = false, b2 = false;
  153. b1 = float.TryParse(textBox1.Text, out oldf);
  154. b2 = float.TryParse(textBox1.Text + e.KeyChar.ToString(), out f);
  155. if (b2 == false)
  156. {
  157. if (b1 == true)
  158. e.Handled = true;
  159. else
  160. e.Handled = false;
  161. }
  162. }
  163. }
  164. }
  165. //private static void OnNumbericLostFocus(object sender, EventArgs e)
  166. //{
  167. // if (areaNow != null && lab != null)
  168. // {
  169. // if (!string.IsNullOrEmpty(lab.Text))
  170. // newWorkType.textboxMessage = lab.Text;
  171. // else
  172. // RemoveOldObject(areaNow, newWorkType);
  173. // areaNow.Controls.Remove(lab);
  174. // areaNow.Refresh();
  175. // clickCount = 0;
  176. // newWorkType = null;
  177. // if (!areaNow.ContinuousDrawingLabel())
  178. // {
  179. // OnMouseUpTwo(areaNow, null);
  180. // }
  181. // }
  182. //}
  183. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  184. {
  185. }
  186. public static void OnMouseClick(ISurfaceBox surfacebox, MouseEventArgs e)
  187. {
  188. }
  189. /// <summary>
  190. /// 鼠标左键双击
  191. /// </summary>
  192. /// <param name="drawArea"></param>
  193. /// <param name="e"></param>
  194. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  195. {
  196. }
  197. /// <summary>
  198. /// 删除按键
  199. /// </summary>
  200. /// <param name="surfacebox"></param>
  201. /// <param name="e"></param>
  202. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  203. {
  204. }
  205. /// <summary>
  206. /// 删除划痕处理&污迹处理选择区域的痕迹
  207. /// </summary>
  208. /// <param name="surfacebox"></param>
  209. /// <param name="e"></param>
  210. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  211. {
  212. }
  213. public static void beginWithNewObject()
  214. {
  215. }
  216. }
  217. }