using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace CowainHmi.UIEditor { public partial class FrmTagEdit : Form { public PlcTagColumn PlcTag { get; set; } public FrmTagEdit(PlcTagColumn tag) { InitializeComponent(); PlcTag = tag; List> enumList = Enum.GetValues(typeof(字段.DatType)) .Cast<字段.DatType>() .Select(e => new KeyValuePair(e.ToString(), e)) .ToList(); // 绑定数据源 cbxType.DisplayMember = "Key"; // 显示枚举的名称 cbxType.ValueMember = "Value"; // 存储枚举的值 cbxType.DataSource = enumList; this.udPLC.Value = tag.PLC; this.txtAddress.Text = tag.Address; this.cbxType.SelectedValue = tag.DatType; this.udDecimalPlaces.Value = tag.DecimalPlaces; this.udStringLength.Value = tag.StringLength; this.txtVarName.Text = tag.VarName; this.txtVarDesc.Text = tag.VarDesc; } private void btnOk_Click(object sender, EventArgs e) { PlcTag = new PlcTagColumn() { PLC = (int)this.udPLC.Value, Address = this.txtAddress.Text, DecimalPlaces = (int)this.udDecimalPlaces.Value, StringLength = (int)this.udStringLength.Value, DatType = (字段.DatType)this.cbxType.SelectedValue, VarName = this.txtVarName.Text, VarDesc = this.txtVarDesc.Text, }; this.DialogResult = DialogResult.OK; } } }