版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

331 lines
11 KiB

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