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

245 строки
7.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. }
  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 double stepData;
  74. [Description("步骤数据")]
  75. [Category("自定义外观")]
  76. public double StepData
  77. {
  78. get { return stepData; }
  79. set
  80. {
  81. stepData = value;
  82. this.RelData.Text = stepData.ToString("0.000");
  83. base.Refresh();
  84. }
  85. }
  86. private double stepMax;
  87. [Description("步骤数据Max")]
  88. [Category("自定义外观")]
  89. public double StepMax
  90. {
  91. get { return stepMax; }
  92. set
  93. {
  94. stepMax = value;
  95. this.MaxValue.Text = stepMax.ToString("0.000");
  96. base.Refresh();
  97. }
  98. }
  99. private double stepMin;
  100. [Description("步骤数据Min")]
  101. [Category("自定义外观")]
  102. public double StepMin
  103. {
  104. get { return stepMin; }
  105. set
  106. {
  107. stepMin = value;
  108. this.MinValue.Text = stepMin.ToString("0.000");
  109. base.Refresh();
  110. }
  111. }
  112. private string stepString;
  113. [Description("数据详细")]
  114. [Category("自定义外观")]
  115. public string StepString
  116. {
  117. get { return stepString; }
  118. set
  119. {
  120. stepString = value;
  121. this.AllDataTextBox.Text = stepString;
  122. base.Refresh();
  123. }
  124. }
  125. public enum StepStsEnum
  126. {
  127. Skip,
  128. Wait,
  129. Testing,
  130. OK,
  131. NG,
  132. Error
  133. }
  134. private StepStsEnum stepStatus;
  135. [Description("步骤状态")]
  136. [Category("自定义外观")]
  137. public StepStsEnum StepStatus
  138. {
  139. get { return stepStatus; }
  140. set
  141. {
  142. stepStatus = value;
  143. switch(stepStatus)
  144. {
  145. case StepStsEnum.Wait:
  146. this.StsLabel.Text = "等待";
  147. this.StsLabel.ForeColor = Color.Black;
  148. break;
  149. case StepStsEnum.Testing:
  150. this.StsLabel.Text = "测试中...";
  151. this.StsLabel.ForeColor = SystemColors.MenuHighlight;
  152. break;
  153. case StepStsEnum.OK:
  154. this.StsLabel.Text = "OK";
  155. this.StsLabel.ForeColor = Color.LimeGreen;
  156. break;
  157. case StepStsEnum.NG:
  158. this.StsLabel.Text = "NG";
  159. this.StsLabel.ForeColor = Color.Red;
  160. break;
  161. case StepStsEnum.Error:
  162. this.StsLabel.Text = "错误";
  163. this.StsLabel.ForeColor = Color.DarkRed;
  164. break;
  165. case StepStsEnum.Skip:
  166. this.StsLabel.Text = "未启用";
  167. this.StsLabel.ForeColor = Color.Black;
  168. break;
  169. }
  170. base.Refresh();
  171. }
  172. }
  173. #endregion
  174. #region Override Methods
  175. /// <summary>
  176. /// 在控件尺寸变化时刷新
  177. /// </summary>
  178. /// <param name="e"></param>
  179. protected override void OnResize(EventArgs e)
  180. {
  181. base.OnResize(e);
  182. base.Refresh();
  183. }
  184. /// <summary>
  185. /// 将控件边框修改成圆角
  186. /// </summary>
  187. /// <param name="e"></param>
  188. protected override void OnPaint(PaintEventArgs e)
  189. {
  190. base.OnPaint(e);
  191. Round(this.Region, RoundRadius);
  192. }
  193. #endregion
  194. #region UI Methods
  195. /// <summary>
  196. /// 绘制控件的圆角
  197. /// </summary>
  198. /// <param name="region"></param>
  199. /// <param name="radius"></param>
  200. public void Round(System.Drawing.Region region, int radius)
  201. {
  202. System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
  203. int x = 0;
  204. int y = 0;
  205. int thisWidth = this.Width;
  206. int thisHeight = this.Height;
  207. int angle = radius;
  208. // 半径非0为圆角矩形
  209. if (angle > 0)
  210. {
  211. System.Drawing.Graphics g = CreateGraphics();
  212. oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
  213. oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
  214. oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
  215. oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
  216. oPath.CloseAllFigures();
  217. Region = new System.Drawing.Region(oPath);
  218. }
  219. //半径为0时为矩形
  220. else
  221. {
  222. angle = 0;
  223. oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
  224. oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
  225. oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
  226. oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
  227. oPath.CloseAllFigures();
  228. Region = new System.Drawing.Region(oPath);
  229. }
  230. }
  231. #endregion
  232. }
  233. }