using LB_VisionProcesses.Alogrithms.Halcon; using LB_VisionProcesses.Alogrithms; using System; using System.Collections.Concurrent; 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; using LB_SmartVision.ProcessRun; namespace LB_SmartVision.Forms.Pages.ProcessPage { public partial class ProcessInputsSelectForm : Form { List listProcessInputsEditControl = new List(); ProcessRunBll ProcessRunBll { get; set; } public ProcessInputsSelectForm() { InitializeComponent(); } public ProcessInputsSelectForm(string ProcessName, ProcessRunBll RunBll) { InitializeComponent(); if (!RunBll.dicInputsMapping.ContainsKey(ProcessName)) return; ProcessRunBll = RunBll; int index = 0; foreach (Tuple tupleInputAndOutput in RunBll.dicInputsMapping[ProcessName]) { string Input = tupleInputAndOutput.Item1; string Output = tupleInputAndOutput.Item2; ProcessInputsEditControl processInputsEditControl = new ProcessInputsEditControl(Input, Output, RunBll.dicInputsMapping, RunBll.dicOutputsMapping); listProcessInputsEditControl.Add(processInputsEditControl); this.panel.Controls.Add(processInputsEditControl); processInputsEditControl.Size = new System.Drawing.Size(panel.Width, 50); processInputsEditControl.Location = new System.Drawing.Point(0, processInputsEditControl.Size.Height * index); index++; } } private void panel_SizeChanged(object sender, EventArgs e) { int index = 0; foreach (var item in listProcessInputsEditControl) { item.Size = new System.Drawing.Size(panel.Width, 50); item.Location = new System.Drawing.Point(0, item.Size.Height * index); index++; } } private void ProcessInputsSelectForm_FormClosing(object sender, FormClosingEventArgs e) { if (ProcessRunBll == null) { e.Cancel = false; //确认关闭窗体 return; } DialogResult res = MessageBox.Show("是否保存?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); //保存结果信息 /// 参数1:显示文本,参数2:标题,参数3:按键类型,参数4:显示图标 if (res != DialogResult.Yes && res != DialogResult.No) //取消 { e.Cancel = true; //取消关闭窗体 return; } if (res == DialogResult.Yes) //保存 { string ProcessName = this.Text; List> tupleInputAndOutput = new List>(); foreach (var control in listProcessInputsEditControl) { string strInput = control.lblInput.Text; string strOutput = control.lblOutput.Text; Tuple tuple = Tuple.Create(strInput, strOutput); tupleInputAndOutput.Add(tuple); } ProcessRunBll.dicInputsMapping.TryRemove(ProcessName, out _); ProcessRunBll.dicInputsMapping.TryAdd(ProcessName, tupleInputAndOutput); e.Cancel = false; //确认关闭窗体 return; } } } }