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 NewStepShowDefect : UserControl
{
public NewStepShowDefect()
{
InitializeComponent();
RoundRadius = 10;
StepName = "步骤名称";
stepIndex = 0;
stepSizeData = -1;
stepDefectData = -1;
stepSizeSts = StepResultEnum.None;
stepDefectSts = StepResultEnum.None;
stepString = "";
stepStatus = StepStsEnum.Error;
}
#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 int stepSizeData;
[Description("比对数据")]
[Category("自定义外观")]
public int StepSizeData
{
get { return stepSizeData; }
set
{
stepSizeData = value;
this.SizeStringLabel.Text = stepSizeData < 0? "无":stepSizeData.ToString();
base.Refresh();
}
}
private int stepDefectData;
[Description("外观数据")]
[Category("自定义外观")]
public int StepDefectData
{
get { return stepDefectData; }
set
{
stepDefectData = value;
this.DefectStringLabel.Text = stepDefectData < 0 ? "无" : stepDefectData.ToString();
base.Refresh();
}
}
public enum StepResultEnum
{
None,
Wait,
OK,
NG,
Error,
Testing,
Done
}
private StepResultEnum stepSizeSts;
[Description("步骤尺寸结果")]
[Category("自定义外观")]
public StepResultEnum StepSizeSts
{
get { return stepSizeSts; }
set
{
stepSizeSts = value;
switch (stepSizeSts)
{
case StepResultEnum.None:
this.SizeRel.Text = "未启用";
this.SizeRel.ForeColor = Color.Black;
break;
case StepResultEnum.Wait:
this.SizeRel.Text = "等待";
this.SizeRel.ForeColor = Color.Black;
break;
case StepResultEnum.OK:
this.SizeRel.Text = "通过";
this.SizeRel.ForeColor = Color.LimeGreen;
break;
case StepResultEnum.NG:
this.SizeRel.Text = "未通过";
this.SizeRel.ForeColor = Color.Red;
break;
case StepResultEnum.Error:
this.SizeRel.Text = "错误";
this.SizeRel.ForeColor = Color.DarkRed;
break;
case StepResultEnum.Testing:
this.SizeRel.Text = "测试中...";
this.SizeRel.ForeColor = SystemColors.MenuHighlight;
break;
case StepResultEnum.Done:
this.SizeRel.Text = "测试完成";
this.SizeRel.ForeColor = Color.Black;
break;
}
base.Refresh();
}
}
private StepResultEnum stepDefectSts;
[Description("步骤尺寸结果")]
[Category("自定义外观")]
public StepResultEnum StepDefectSts
{
get { return stepDefectSts; }
set
{
stepDefectSts = value;
switch (stepDefectSts)
{
case StepResultEnum.None:
this.DefectRel.Text = "未启用";
this.DefectRel.ForeColor = Color.Black;
break;
case StepResultEnum.Wait:
this.DefectRel.Text = "等待";
this.DefectRel.ForeColor = Color.Black;
break;
case StepResultEnum.OK:
this.DefectRel.Text = "通过";
this.DefectRel.ForeColor = Color.LimeGreen;
break;
case StepResultEnum.NG:
this.DefectRel.Text = "未通过";
this.DefectRel.ForeColor = Color.Red;
break;
case StepResultEnum.Error:
this.DefectRel.Text = "错误";
this.DefectRel.ForeColor = Color.DarkRed;
break;
case StepResultEnum.Testing:
this.DefectRel.Text = "测试中...";
this.DefectRel.ForeColor = SystemColors.MenuHighlight;
break;
case StepResultEnum.Done:
this.DefectRel.Text = "测试完成";
this.DefectRel.ForeColor = Color.Black;
break;
}
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
{
Wait,
Testing,
OK,
NG,
Error,
Skip
}
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
///
/// 在控件尺寸变化时刷新
///
///
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
base.Refresh();
}
///
/// 将控件边框修改成圆角
///
///
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Round(this.Region, RoundRadius);
}
#endregion
#region UI Methods
///
/// 绘制控件的圆角
///
///
///
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
}
}