using System.ComponentModel; using System.Reflection; using AntdUI; using DH.Commons.Base; using DH.Commons.Enums; using DH.Devices.Vision; using static System.Windows.Forms.AxHost; namespace DHSoftware.Views { public partial class DetectionLableEdit : UserControl { private AntdUI.Window window; private DetectionLable detectionLable; public bool submit; public DetectionLableEdit(AntdUI.Window _window, DetectionLable detection) { this.window = _window; detectionLable = detection; InitializeComponent(); //设置默认值 InitData(); // 绑定事件 BindEventHandler(); } private void BindEventHandler() { button_ok.Click += Button_ok_Click; button_cancel.Click += Button_cancel_Click; } private void Button_cancel_Click(object sender, EventArgs e) { submit = false; this.Dispose(); } private void Button_ok_Click(object sender, EventArgs e) { iptName.Status = AntdUI.TType.None; //检查输入内容 if (String.IsNullOrEmpty(iptName.Text)) { iptName.Status = AntdUI.TType.Error; AntdUI.Message.warn(window, "参数名称不能为空!", autoClose: 3); return; } detectionLable.LabelName = iptName.Text; detectionLable.MinSource=Convert.ToDouble(iptMinSource.Text); detectionLable.MaxSource = Convert.ToDouble(iptMaxSource.Text); detectionLable.MinArea = Convert.ToDouble(iptMinArea.Text); detectionLable.MaxArea = Convert.ToDouble(iptMaxArea.Text); ResultState state = EnumHelper.GetEnumFromDescription(sltResultState.Text); detectionLable.ResultState = state; submit = true; this.Dispose(); } private void InitData() { // 清空原有项 sltResultState.Items.Clear(); foreach (ResultState state in Enum.GetValues(typeof(ResultState))) { string description = EnumHelper.GetEnumDescription(state); sltResultState.Items.Add(description); } if (string.IsNullOrEmpty(detectionLable.LabelName)) { iptName.Text = string.Empty; iptMinSource.Text = "0.3"; iptMaxSource.Text = "1"; iptMinArea.Text = "0"; iptMaxArea.Text = "99999999"; sltResultState.SelectedIndex = 0; } else { iptName.Text = detectionLable.LabelName; iptMinSource.Text = detectionLable.MinSource.ToString(); iptMaxSource.Text = detectionLable.MaxSource.ToString(); iptMinArea.Text = detectionLable.MinArea.ToString(); iptMaxArea.Text = detectionLable.MaxArea.ToString(); sltResultState.Text= EnumHelper.GetEnumDescription(detectionLable.ResultState); } } } }