|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- using CCWin.SkinControl;
- using MaiMuAOI.Properties;
- using System;
- using System.Collections;
- 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;
- tlimit = "";
- }
-
- #region Properties
- 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("0.000");
- base.Refresh();
- }
- }
-
- private double stepMax;
- [Description("步骤数据Max")]
- [Category("自定义外观")]
- public double StepMax
- {
- get { return stepMax; }
- set
- {
- stepMax = value;
- this.MaxValue.Text = stepMax.ToString("0.000");
- base.Refresh();
- }
- }
- private double stepMin;
- [Description("步骤数据Min")]
- [Category("自定义外观")]
- public double StepMin
- {
- get { return stepMin; }
- set
- {
- stepMin = value;
- this.MinValue.Text = stepMin.ToString("0.000");
- base.Refresh();
- }
- }
-
- private string tlimit;
- [Description("步骤数据limit")]
- [Category("自定义外观")]
- public string TLimit
- {
- get { return tlimit; }
- set
- {
- tlimit = value;
- this.Limit.Text = tlimit;
- base.Refresh();
- }
- }
-
- private string stepString;
- [Description("数据详细")]
- [Category("自定义外观")]
- public string StepString
- {
- get { return stepString; }
- set
- {
- stepString = value;
- //this.AllDataTextBox.Text = stepString;
- this.AllDataTextBox.AppendText(stepString + "\r\n");
- //this.AllDataTextBox.AppendText(stepString);
- base.Refresh();
- }
- }
- public void ClearText()
- {
- this.AllDataTextBox.Clear();
- }
- private bool enabel;
- public bool Enabel
- {
- get { return enabel; }
- set
- {
- enabel = value;
- if (enabel)
- this.pictureBox1.Image = Resources.使用中;
- else
- this.pictureBox1.Image = Resources.停用_底;
- base.Refresh();
- }
- }
-
- private bool showenabel = true;
- public bool ShowEnabel
- {
- get { return showenabel; }
- set
- {
- showenabel = value;
- this.pictureBox1.Visible = showenabel;
- base.Refresh();
- }
- }
-
- public Action<int, bool> EnabelChangeEvent;
- 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();
- }
- }
-
-
- private ArrayList getIndexArray(String inputStr, String findStr)//找出对应目下标
- {
- ArrayList list = new ArrayList();
- int start = 0;
- while (start < inputStr.Length)
- {
- int index = inputStr.IndexOf(findStr, start);
- if (index >= 0)
- {
- list.Add(index);
- start = index + findStr.Length;
- }
- else
- {
- break;
- }
- }
- return list;
- }
-
- public void SetRedString(string redString)
- {
- //this.AllDataTextBox.SelectedText = redString;//选择当前行数追加内容
- string strt = redString;
- ArrayList list = getIndexArray(this.AllDataTextBox.Text, strt);
- for (int i = 0; i < list.Count; i++)
- {
- int index = (int)list[i];
- AllDataTextBox.Select(index, strt.Length);//设置当前文本对象
- AllDataTextBox.SelectionColor = Color.Red;//设置文本对象颜色
- 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
-
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- this.Enabel = !enabel;
-
- EnabelChangeEvent?.Invoke(stepIndex - 1, enabel);
- }
- }
- }
|