版博士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.
 
 
 
 

283 lines
8.7 KiB

  1. using CCWin.SkinControl;
  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 NewStepShow : UserControl
  14. {
  15. public NewStepShow()
  16. {
  17. InitializeComponent();
  18. RoundRadius = 10;
  19. StepName = "步骤名称";
  20. stepIndex = 0;
  21. stepData = 0.000;
  22. stepMax = 0.000;
  23. stepMin = 0.000;
  24. stepString = "";
  25. stepStatus = StepStsEnum.Error;
  26. dl = "f4";
  27. daralen = 4;
  28. }
  29. #region Properties
  30. private string dl = "";
  31. private int daralen;
  32. [Description("数据显示长度")]
  33. [Category("自定义外观")]
  34. public int DataLen
  35. {
  36. get { return daralen; }
  37. set
  38. {
  39. if (value <= 0)
  40. {
  41. daralen = 4;
  42. dl = "f4";
  43. }
  44. else
  45. {
  46. daralen = value;
  47. dl = $"f{daralen}";
  48. }
  49. base.Refresh();
  50. }
  51. }
  52. private int roundRadius;
  53. [Description("圆角半径(0为不要圆角)")]
  54. [Category("自定义外观")]
  55. public int RoundRadius
  56. {
  57. get { return roundRadius; }
  58. set
  59. {
  60. if (value < 0)
  61. {
  62. roundRadius = 0;
  63. }
  64. else
  65. {
  66. roundRadius = value;
  67. }
  68. base.Refresh();
  69. }
  70. }
  71. private string stepName;
  72. [Description("步骤名称")]
  73. [Category("自定义外观")]
  74. public string StepName
  75. {
  76. get { return stepName; }
  77. set
  78. {
  79. stepName = value;
  80. this.NameLabel.Text = stepName;
  81. base.Refresh();
  82. }
  83. }
  84. private int stepIndex;
  85. [Description("步骤序号")]
  86. [Category("自定义外观")]
  87. public int StepIndex
  88. {
  89. get { return stepIndex; }
  90. set
  91. {
  92. stepIndex = value;
  93. this.IndexLabel.Text = stepIndex.ToString();
  94. base.Refresh();
  95. }
  96. }
  97. private double stepData;
  98. [Description("步骤数据")]
  99. [Category("自定义外观")]
  100. public double StepData
  101. {
  102. get { return stepData; }
  103. set
  104. {
  105. stepData = value;
  106. this.RelData.Text = stepData.ToString(dl);
  107. base.Refresh();
  108. }
  109. }
  110. private double stepMax;
  111. [Description("步骤数据Max")]
  112. [Category("自定义外观")]
  113. public double StepMax
  114. {
  115. get { return stepMax; }
  116. set
  117. {
  118. stepMax = value;
  119. this.MaxValue.Text = stepMax.ToString(dl);
  120. base.Refresh();
  121. }
  122. }
  123. private double stepMin;
  124. [Description("步骤数据Min")]
  125. [Category("自定义外观")]
  126. public double StepMin
  127. {
  128. get { return stepMin; }
  129. set
  130. {
  131. stepMin = value;
  132. this.MinValue.Text = stepMin.ToString(dl);
  133. base.Refresh();
  134. }
  135. }
  136. private double stepMaxMin;
  137. [Description("步骤数据极差")]
  138. [Category("自定义外观")]
  139. public double StepMaxMin
  140. {
  141. get { return stepMaxMin; }
  142. set
  143. {
  144. stepMaxMin = value;
  145. this.JCValue.Text = stepMaxMin.ToString(dl);
  146. base.Refresh();
  147. }
  148. }
  149. private string stepString;
  150. [Description("数据详细")]
  151. [Category("自定义外观")]
  152. public string StepString
  153. {
  154. get { return stepString; }
  155. set
  156. {
  157. stepString = value;
  158. this.AllDataTextBox.Text = stepString;
  159. base.Refresh();
  160. }
  161. }
  162. public enum StepStsEnum
  163. {
  164. Skip,
  165. Wait,
  166. Testing,
  167. OK,
  168. NG,
  169. Error
  170. }
  171. private StepStsEnum stepStatus;
  172. [Description("步骤状态")]
  173. [Category("自定义外观")]
  174. public StepStsEnum StepStatus
  175. {
  176. get { return stepStatus; }
  177. set
  178. {
  179. stepStatus = value;
  180. switch(stepStatus)
  181. {
  182. case StepStsEnum.Wait:
  183. this.StsLabel.Text = "等待";
  184. this.StsLabel.ForeColor = Color.Black;
  185. break;
  186. case StepStsEnum.Testing:
  187. this.StsLabel.Text = "测试中...";
  188. this.StsLabel.ForeColor = SystemColors.MenuHighlight;
  189. break;
  190. case StepStsEnum.OK:
  191. this.StsLabel.Text = "OK";
  192. this.StsLabel.ForeColor = Color.LimeGreen;
  193. break;
  194. case StepStsEnum.NG:
  195. this.StsLabel.Text = "NG";
  196. this.StsLabel.ForeColor = Color.Red;
  197. break;
  198. case StepStsEnum.Error:
  199. this.StsLabel.Text = "错误";
  200. this.StsLabel.ForeColor = Color.DarkRed;
  201. break;
  202. case StepStsEnum.Skip:
  203. this.StsLabel.Text = "未启用";
  204. this.StsLabel.ForeColor = Color.Black;
  205. break;
  206. }
  207. base.Refresh();
  208. }
  209. }
  210. #endregion
  211. #region Override Methods
  212. /// <summary>
  213. /// 在控件尺寸变化时刷新
  214. /// </summary>
  215. /// <param name="e"></param>
  216. protected override void OnResize(EventArgs e)
  217. {
  218. base.OnResize(e);
  219. base.Refresh();
  220. }
  221. /// <summary>
  222. /// 将控件边框修改成圆角
  223. /// </summary>
  224. /// <param name="e"></param>
  225. protected override void OnPaint(PaintEventArgs e)
  226. {
  227. base.OnPaint(e);
  228. Round(this.Region, RoundRadius);
  229. }
  230. #endregion
  231. #region UI Methods
  232. /// <summary>
  233. /// 绘制控件的圆角
  234. /// </summary>
  235. /// <param name="region"></param>
  236. /// <param name="radius"></param>
  237. public void Round(System.Drawing.Region region, int radius)
  238. {
  239. System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
  240. int x = 0;
  241. int y = 0;
  242. int thisWidth = this.Width;
  243. int thisHeight = this.Height;
  244. int angle = radius;
  245. // 半径非0为圆角矩形
  246. if (angle > 0)
  247. {
  248. System.Drawing.Graphics g = CreateGraphics();
  249. oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
  250. oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
  251. oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
  252. oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
  253. oPath.CloseAllFigures();
  254. Region = new System.Drawing.Region(oPath);
  255. }
  256. //半径为0时为矩形
  257. else
  258. {
  259. angle = 0;
  260. oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
  261. oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
  262. oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
  263. oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
  264. oPath.CloseAllFigures();
  265. Region = new System.Drawing.Region(oPath);
  266. }
  267. }
  268. #endregion
  269. }
  270. }