|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- using CCWin.SkinControl;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace MaiMuAOI.SysUI.ProcessStep.Ctrl
- {
- public partial class NewStepShow : UserControl
- {
- public NewStepShow()
- {
- InitializeComponent();
- RoundRadius = 10;
- StepName = "步骤名称";
- stepIndex = 0;
- stepData = 0.000;
- stepMax = 0.000;
- stepMin = 0.000;
- stepString = "";
- stepStatus = StepStsEnum.Error;
- dl = "f4";
- daralen = 4;
- }
-
- #region Properties
- private string dl = "";
- private int daralen;
- [Description("数据显示长度")]
- [Category("自定义外观")]
- public int DataLen
- {
- get { return daralen; }
- set
- {
- if (value <= 0)
- {
- daralen = 4;
- dl = "f4";
- }
- else
- {
- daralen = value;
- dl = $"f{daralen}";
- }
- base.Refresh();
- }
- }
-
- private int roundRadius;
- [Description("圆角半径(0为不要圆角)")]
- [Category("自定义外观")]
- public int RoundRadius
- {
- get { return roundRadius; }
- set
- {
- if (value < 0)
- {
- roundRadius = 0;
- }
- else
- {
- roundRadius = value;
- }
- base.Refresh();
- }
- }
-
- private string stepName;
- [Description("步骤名称")]
- [Category("自定义外观")]
- public string StepName
- {
- get { return stepName; }
- set
- {
- stepName = value;
- this.NameLabel.Text = stepName;
- base.Refresh();
- }
- }
-
- private int stepIndex;
- [Description("步骤序号")]
- [Category("自定义外观")]
- public int StepIndex
- {
- get { return stepIndex; }
- set
- {
- stepIndex = value;
- this.IndexLabel.Text = stepIndex.ToString();
- base.Refresh();
- }
- }
-
- private double stepData;
- [Description("步骤数据")]
- [Category("自定义外观")]
- public double StepData
- {
- get { return stepData; }
- set
- {
- stepData = value;
- this.RelData.Text = stepData.ToString(dl);
- base.Refresh();
- }
- }
-
- private double stepMax;
- [Description("步骤数据Max")]
- [Category("自定义外观")]
- public double StepMax
- {
- get { return stepMax; }
- set
- {
- stepMax = value;
- this.MaxValue.Text = stepMax.ToString(dl);
- base.Refresh();
- }
- }
- private double stepMin;
- [Description("步骤数据Min")]
- [Category("自定义外观")]
- public double StepMin
- {
- get { return stepMin; }
- set
- {
- stepMin = value;
- this.MinValue.Text = stepMin.ToString(dl);
- base.Refresh();
- }
- }
- private double stepMaxMin;
- [Description("步骤数据极差")]
- [Category("自定义外观")]
- public double StepMaxMin
- {
- get { return stepMaxMin; }
- set
- {
- stepMaxMin = value;
- this.JCValue.Text = stepMaxMin.ToString(dl);
- base.Refresh();
- }
- }
-
- private string stepString;
- [Description("数据详细")]
- [Category("自定义外观")]
- public string StepString
- {
- get { return stepString; }
- set
- {
- stepString = value;
- this.AllDataTextBox.Text = stepString;
- base.Refresh();
- }
- }
-
- public enum StepStsEnum
- {
- Skip,
- Wait,
- Testing,
- OK,
- NG,
- Error
- }
- private StepStsEnum stepStatus;
- [Description("步骤状态")]
- [Category("自定义外观")]
- public StepStsEnum StepStatus
- {
- get { return stepStatus; }
- set
- {
- stepStatus = value;
- switch(stepStatus)
- {
- case StepStsEnum.Wait:
- this.StsLabel.Text = "等待";
- this.StsLabel.ForeColor = Color.Black;
- break;
- case StepStsEnum.Testing:
- this.StsLabel.Text = "测试中...";
- this.StsLabel.ForeColor = SystemColors.MenuHighlight;
- break;
- case StepStsEnum.OK:
- this.StsLabel.Text = "OK";
- this.StsLabel.ForeColor = Color.LimeGreen;
- break;
- case StepStsEnum.NG:
- this.StsLabel.Text = "NG";
- this.StsLabel.ForeColor = Color.Red;
- break;
- case StepStsEnum.Error:
- this.StsLabel.Text = "错误";
- this.StsLabel.ForeColor = Color.DarkRed;
- break;
- case StepStsEnum.Skip:
- this.StsLabel.Text = "未启用";
- this.StsLabel.ForeColor = Color.Black;
- break;
- }
-
- base.Refresh();
- }
- }
- #endregion
-
- #region Override Methods
- /// <summary>
- /// 在控件尺寸变化时刷新
- /// </summary>
- /// <param name="e"></param>
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- base.Refresh();
- }
- /// <summary>
- /// 将控件边框修改成圆角
- /// </summary>
- /// <param name="e"></param>
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- Round(this.Region, RoundRadius);
- }
- #endregion
-
- #region UI Methods
- /// <summary>
- /// 绘制控件的圆角
- /// </summary>
- /// <param name="region"></param>
- /// <param name="radius"></param>
- public void Round(System.Drawing.Region region, int radius)
- {
- System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
- int x = 0;
- int y = 0;
- int thisWidth = this.Width;
- int thisHeight = this.Height;
- int angle = radius;
- // 半径非0为圆角矩形
- if (angle > 0)
- {
- System.Drawing.Graphics g = CreateGraphics();
- oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
- oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
- oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
- oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
- oPath.CloseAllFigures();
- Region = new System.Drawing.Region(oPath);
- }
- //半径为0时为矩形
- else
- {
- angle = 0;
- oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
- oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
- oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
- oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
- oPath.CloseAllFigures();
- Region = new System.Drawing.Region(oPath);
- }
- }
- #endregion
- }
- }
|