版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

NewStepShowDefect.cs 12 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. using MaiMuAOI.Properties;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace MaiMuAOI.SysUI.ProcessStep.Ctrl
  12. {
  13. public partial class NewStepShowDefect : UserControl
  14. {
  15. public NewStepShowDefect()
  16. {
  17. InitializeComponent();
  18. RoundRadius = 10;
  19. StepName = "步骤名称";
  20. stepIndex = 0;
  21. stepSizeData = -1;
  22. stepDefectData = -1;
  23. stepSizeSts = StepResultEnum.None;
  24. stepDefectSts = StepResultEnum.None;
  25. stepString = "";
  26. stepStatus = StepStsEnum.Error;
  27. }
  28. #region Properties
  29. private int roundRadius;
  30. [Description("圆角半径(0为不要圆角)")]
  31. [Category("自定义外观")]
  32. public int RoundRadius
  33. {
  34. get { return roundRadius; }
  35. set
  36. {
  37. if (value < 0)
  38. {
  39. roundRadius = 0;
  40. }
  41. else
  42. {
  43. roundRadius = value;
  44. }
  45. base.Refresh();
  46. }
  47. }
  48. private string stepName;
  49. [Description("步骤名称")]
  50. [Category("自定义外观")]
  51. public string StepName
  52. {
  53. get { return stepName; }
  54. set
  55. {
  56. stepName = value;
  57. this.NameLabel.Text = stepName;
  58. base.Refresh();
  59. }
  60. }
  61. private int stepIndex;
  62. [Description("步骤序号")]
  63. [Category("自定义外观")]
  64. public int StepIndex
  65. {
  66. get { return stepIndex; }
  67. set
  68. {
  69. stepIndex = value;
  70. this.IndexLabel.Text = stepIndex.ToString();
  71. base.Refresh();
  72. }
  73. }
  74. private int stepSizeData;
  75. [Description("比对数据")]
  76. [Category("自定义外观")]
  77. public int StepSizeData
  78. {
  79. get { return stepSizeData; }
  80. set
  81. {
  82. stepSizeData = value;
  83. this.SizeStringLabel.Text = stepSizeData < 0? "无":stepSizeData.ToString();
  84. base.Refresh();
  85. }
  86. }
  87. private int stepDefectData;
  88. [Description("外观数据")]
  89. [Category("自定义外观")]
  90. public int StepDefectData
  91. {
  92. get { return stepDefectData; }
  93. set
  94. {
  95. stepDefectData = value;
  96. this.DefectStringLabel.Text = stepDefectData < 0 ? "无" : stepDefectData.ToString();
  97. base.Refresh();
  98. }
  99. }
  100. private bool enabel;
  101. public bool Enabel
  102. {
  103. get { return enabel; }
  104. set
  105. {
  106. enabel = value;
  107. if (enabel)
  108. this.pictureBox1.Image = Resources.使用中;
  109. else
  110. this.pictureBox1.Image = Resources.停用_底;
  111. base.Refresh();
  112. }
  113. }
  114. public Action<int, bool> EnabelChangeEvent;
  115. public enum StepResultEnum
  116. {
  117. None,
  118. Wait,
  119. OK,
  120. NG,
  121. Error,
  122. Testing,
  123. Done
  124. }
  125. private StepResultEnum stepSizeSts;
  126. [Description("步骤尺寸结果")]
  127. [Category("自定义外观")]
  128. public StepResultEnum StepSizeSts
  129. {
  130. get { return stepSizeSts; }
  131. set
  132. {
  133. stepSizeSts = value;
  134. switch (stepSizeSts)
  135. {
  136. case StepResultEnum.None:
  137. this.SizeRel.Text = "未启用";
  138. this.SizeRel.ForeColor = Color.Black;
  139. break;
  140. case StepResultEnum.Wait:
  141. this.SizeRel.Text = "等待";
  142. this.SizeRel.ForeColor = Color.Black;
  143. break;
  144. case StepResultEnum.OK:
  145. this.SizeRel.Text = "通过";
  146. this.SizeRel.ForeColor = Color.LimeGreen;
  147. break;
  148. case StepResultEnum.NG:
  149. this.SizeRel.Text = "未通过";
  150. this.SizeRel.ForeColor = Color.Red;
  151. break;
  152. case StepResultEnum.Error:
  153. this.SizeRel.Text = "错误";
  154. this.SizeRel.ForeColor = Color.DarkRed;
  155. break;
  156. case StepResultEnum.Testing:
  157. this.SizeRel.Text = "测试中...";
  158. this.SizeRel.ForeColor = SystemColors.MenuHighlight;
  159. break;
  160. case StepResultEnum.Done:
  161. this.SizeRel.Text = "测试完成";
  162. this.SizeRel.ForeColor = Color.Black;
  163. break;
  164. }
  165. base.Refresh();
  166. }
  167. }
  168. private StepResultEnum stepDefectSts;
  169. [Description("步骤尺寸结果")]
  170. [Category("自定义外观")]
  171. public StepResultEnum StepDefectSts
  172. {
  173. get { return stepDefectSts; }
  174. set
  175. {
  176. stepDefectSts = value;
  177. switch (stepDefectSts)
  178. {
  179. case StepResultEnum.None:
  180. this.DefectRel.Text = "未启用";
  181. this.DefectRel.ForeColor = Color.Black;
  182. break;
  183. case StepResultEnum.Wait:
  184. this.DefectRel.Text = "等待";
  185. this.DefectRel.ForeColor = Color.Black;
  186. break;
  187. case StepResultEnum.OK:
  188. this.DefectRel.Text = "通过";
  189. this.DefectRel.ForeColor = Color.LimeGreen;
  190. break;
  191. case StepResultEnum.NG:
  192. this.DefectRel.Text = "未通过";
  193. this.DefectRel.ForeColor = Color.Red;
  194. break;
  195. case StepResultEnum.Error:
  196. this.DefectRel.Text = "错误";
  197. this.DefectRel.ForeColor = Color.DarkRed;
  198. break;
  199. case StepResultEnum.Testing:
  200. this.DefectRel.Text = "测试中...";
  201. this.DefectRel.ForeColor = SystemColors.MenuHighlight;
  202. break;
  203. case StepResultEnum.Done:
  204. this.DefectRel.Text = "测试完成";
  205. this.DefectRel.ForeColor = Color.Black;
  206. break;
  207. }
  208. base.Refresh();
  209. }
  210. }
  211. private string stepString;
  212. [Description("数据详细")]
  213. [Category("自定义外观")]
  214. public string StepString
  215. {
  216. get { return stepString; }
  217. set
  218. {
  219. stepString = value;
  220. this.AllDataTextBox.Text = stepString;
  221. base.Refresh();
  222. }
  223. }
  224. public enum StepStsEnum
  225. {
  226. Wait,
  227. Testing,
  228. OK,
  229. NG,
  230. Error,
  231. Skip
  232. }
  233. private StepStsEnum stepStatus;
  234. [Description("步骤状态")]
  235. [Category("自定义外观")]
  236. public StepStsEnum StepStatus
  237. {
  238. get { return stepStatus; }
  239. set
  240. {
  241. stepStatus = value;
  242. switch (stepStatus)
  243. {
  244. case StepStsEnum.Wait:
  245. this.StsLabel.Text = "等待";
  246. this.StsLabel.ForeColor = Color.Black;
  247. break;
  248. case StepStsEnum.Testing:
  249. this.StsLabel.Text = "测试中...";
  250. this.StsLabel.ForeColor = SystemColors.MenuHighlight;
  251. break;
  252. case StepStsEnum.OK:
  253. this.StsLabel.Text = "OK";
  254. this.StsLabel.ForeColor = Color.LimeGreen;
  255. break;
  256. case StepStsEnum.NG:
  257. this.StsLabel.Text = "NG";
  258. this.StsLabel.ForeColor = Color.Red;
  259. break;
  260. case StepStsEnum.Error:
  261. this.StsLabel.Text = "错误";
  262. this.StsLabel.ForeColor = Color.DarkRed;
  263. break;
  264. case StepStsEnum.Skip:
  265. this.StsLabel.Text = "未启用";
  266. this.StsLabel.ForeColor = Color.Black;
  267. break;
  268. }
  269. base.Refresh();
  270. }
  271. }
  272. #endregion
  273. #region Override Methods
  274. /// <summary>
  275. /// 在控件尺寸变化时刷新
  276. /// </summary>
  277. /// <param name="e"></param>
  278. protected override void OnResize(EventArgs e)
  279. {
  280. base.OnResize(e);
  281. base.Refresh();
  282. }
  283. /// <summary>
  284. /// 将控件边框修改成圆角
  285. /// </summary>
  286. /// <param name="e"></param>
  287. protected override void OnPaint(PaintEventArgs e)
  288. {
  289. base.OnPaint(e);
  290. Round(this.Region, RoundRadius);
  291. }
  292. #endregion
  293. #region UI Methods
  294. /// <summary>
  295. /// 绘制控件的圆角
  296. /// </summary>
  297. /// <param name="region"></param>
  298. /// <param name="radius"></param>
  299. public void Round(System.Drawing.Region region, int radius)
  300. {
  301. System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
  302. int x = 0;
  303. int y = 0;
  304. int thisWidth = this.Width;
  305. int thisHeight = this.Height;
  306. int angle = radius;
  307. // 半径非0为圆角矩形
  308. if (angle > 0)
  309. {
  310. System.Drawing.Graphics g = CreateGraphics();
  311. oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
  312. oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
  313. oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
  314. oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
  315. oPath.CloseAllFigures();
  316. Region = new System.Drawing.Region(oPath);
  317. }
  318. //半径为0时为矩形
  319. else
  320. {
  321. angle = 0;
  322. oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
  323. oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
  324. oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
  325. oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
  326. oPath.CloseAllFigures();
  327. Region = new System.Drawing.Region(oPath);
  328. }
  329. }
  330. #endregion
  331. private void pictureBox1_Click(object sender, EventArgs e)
  332. {
  333. this.Enabel = !enabel;
  334. EnabelChangeEvent?.Invoke(stepIndex - 1, enabel);
  335. }
  336. }
  337. }