版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

352 строки
11 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. public void ShowLimit(bool val)
  111. {
  112. label4.Visible = val;
  113. label5.Visible = val;
  114. label6.Visible = val;
  115. MaxLimit.Visible = val;
  116. MinLimit.Visible = val;
  117. stVal.Visible = val;
  118. }
  119. public void ShowLimitAndVal(bool val)
  120. {
  121. //label1.Visible = val;
  122. //label2.Visible = val;
  123. //label3.Visible = val;
  124. label4.Visible = val;
  125. label5.Visible = val;
  126. label6.Visible = val;
  127. MaxLimit.Visible = val;
  128. MinLimit.Visible = val;
  129. //MaxValue.Visible = val;
  130. //MinValue.Visible = val;
  131. stVal.Visible = val;
  132. //JCValue.Visible = val;
  133. //RelData.Visible = val;
  134. }
  135. private double stdVal;
  136. [Description("标准值")]
  137. [Category("自定义外观")]
  138. public double StdVal
  139. {
  140. get { return stdVal; }
  141. set
  142. {
  143. stdVal = value;
  144. this.stVal.Text = stdVal.ToString(dl);
  145. base.Refresh();
  146. }
  147. }
  148. private double limitMax;
  149. [Description("数据Max")]
  150. [Category("自定义外观")]
  151. public double LimitMax
  152. {
  153. get { return limitMax; }
  154. set
  155. {
  156. limitMax = value;
  157. this.MaxLimit.Text = limitMax.ToString(dl);
  158. base.Refresh();
  159. }
  160. }
  161. private double limitMin;
  162. [Description("数据Min")]
  163. [Category("自定义外观")]
  164. public double LimitMin
  165. {
  166. get { return limitMin; }
  167. set
  168. {
  169. limitMin = value;
  170. this.MinLimit.Text = limitMin.ToString(dl);
  171. base.Refresh();
  172. }
  173. }
  174. private double stepMax;
  175. [Description("步骤数据Max")]
  176. [Category("自定义外观")]
  177. public double StepMax
  178. {
  179. get { return stepMax; }
  180. set
  181. {
  182. stepMax = value;
  183. this.MaxValue.Text = stepMax.ToString(dl);
  184. base.Refresh();
  185. }
  186. }
  187. private double stepMin;
  188. [Description("步骤数据Min")]
  189. [Category("自定义外观")]
  190. public double StepMin
  191. {
  192. get { return stepMin; }
  193. set
  194. {
  195. stepMin = value;
  196. this.MinValue.Text = stepMin.ToString(dl);
  197. base.Refresh();
  198. }
  199. }
  200. private double stepMaxMin;
  201. [Description("步骤数据极差")]
  202. [Category("自定义外观")]
  203. public double StepMaxMin
  204. {
  205. get { return stepMaxMin; }
  206. set
  207. {
  208. stepMaxMin = value;
  209. this.JCValue.Text = stepMaxMin.ToString(dl);
  210. base.Refresh();
  211. }
  212. }
  213. private string stepString;
  214. [Description("数据详细")]
  215. [Category("自定义外观")]
  216. public string StepString
  217. {
  218. get { return stepString; }
  219. set
  220. {
  221. stepString = value;
  222. this.AllDataTextBox.Text = stepString;
  223. base.Refresh();
  224. }
  225. }
  226. public enum StepStsEnum
  227. {
  228. Skip,
  229. Wait,
  230. Testing,
  231. OK,
  232. NG,
  233. Error
  234. }
  235. private StepStsEnum stepStatus;
  236. [Description("步骤状态")]
  237. [Category("自定义外观")]
  238. public StepStsEnum StepStatus
  239. {
  240. get { return stepStatus; }
  241. set
  242. {
  243. stepStatus = value;
  244. switch(stepStatus)
  245. {
  246. case StepStsEnum.Wait:
  247. this.StsLabel.Text = "等待";
  248. this.StsLabel.ForeColor = Color.Black;
  249. break;
  250. case StepStsEnum.Testing:
  251. this.StsLabel.Text = "测试中...";
  252. this.StsLabel.ForeColor = SystemColors.MenuHighlight;
  253. break;
  254. case StepStsEnum.OK:
  255. this.StsLabel.Text = "OK";
  256. this.StsLabel.ForeColor = Color.LimeGreen;
  257. break;
  258. case StepStsEnum.NG:
  259. this.StsLabel.Text = "NG";
  260. this.StsLabel.ForeColor = Color.Red;
  261. break;
  262. case StepStsEnum.Error:
  263. this.StsLabel.Text = "错误";
  264. this.StsLabel.ForeColor = Color.DarkRed;
  265. break;
  266. case StepStsEnum.Skip:
  267. this.StsLabel.Text = "未启用";
  268. this.StsLabel.ForeColor = Color.Black;
  269. break;
  270. }
  271. base.Refresh();
  272. }
  273. }
  274. #endregion
  275. #region Override Methods
  276. /// <summary>
  277. /// 在控件尺寸变化时刷新
  278. /// </summary>
  279. /// <param name="e"></param>
  280. protected override void OnResize(EventArgs e)
  281. {
  282. base.OnResize(e);
  283. base.Refresh();
  284. }
  285. /// <summary>
  286. /// 将控件边框修改成圆角
  287. /// </summary>
  288. /// <param name="e"></param>
  289. protected override void OnPaint(PaintEventArgs e)
  290. {
  291. base.OnPaint(e);
  292. Round(this.Region, RoundRadius);
  293. }
  294. #endregion
  295. #region UI Methods
  296. /// <summary>
  297. /// 绘制控件的圆角
  298. /// </summary>
  299. /// <param name="region"></param>
  300. /// <param name="radius"></param>
  301. public void Round(System.Drawing.Region region, int radius)
  302. {
  303. System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
  304. int x = 0;
  305. int y = 0;
  306. int thisWidth = this.Width;
  307. int thisHeight = this.Height;
  308. int angle = radius;
  309. // 半径非0为圆角矩形
  310. if (angle > 0)
  311. {
  312. System.Drawing.Graphics g = CreateGraphics();
  313. oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
  314. oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
  315. oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
  316. oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
  317. oPath.CloseAllFigures();
  318. Region = new System.Drawing.Region(oPath);
  319. }
  320. //半径为0时为矩形
  321. else
  322. {
  323. angle = 0;
  324. oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
  325. oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
  326. oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
  327. oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
  328. oPath.CloseAllFigures();
  329. Region = new System.Drawing.Region(oPath);
  330. }
  331. }
  332. #endregion
  333. }
  334. }