using LB_VisionProcesses; using LB_VisionProcesses.Forms; 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 LB_SmartVision.Forms.Pages.SettingPage { public partial class LayoutPage : UserControl { public LayoutPage() { InitializeComponent(); btnSave.Click += (sender, e) => { if (!VisionForm.SaveAllLayout()) { MessageBox.Show("!!!保存失败!!!", "异常"); } else { MessageBox.Show("保存成功!"); } }; } private void LayoutPage_Paint(object sender, PaintEventArgs e) { this.pnlLayout.Controls.Clear(); for (int index = 0; index < GlobalVar.dicLayout.Count; index++) { try { LayoutSettingControl control = new LayoutSettingControl(GlobalVar.dicLayout[index]); control.Size = new Size(this.pnlLayout.Size.Width, control.Size.Height); control.Location = new Point(0, control.Size.Height * index); this.pnlLayout.Controls.Add(control); } catch { } } } private void btnAdd_Click(object sender, EventArgs e) { Layout layout = new Layout(GlobalVar.strApplicationPath + "\\生产图片"); foreach (var item in GlobalVar.dicLayout.Values) { if (item.Title == layout.Title) { layout.Title += "(副本)"; } } GlobalVar.dicLayout.TryAdd(GlobalVar.dicLayout.Count, layout); this.Invalidate(); } private void btnDel_Click(object sender, EventArgs e) { foreach (var control in pnlLayout.Controls) { if (control is LayoutSettingControl layoutSettingControl && layoutSettingControl.IsSelected) { var item = GlobalVar.dicLayout.FirstOrDefault(x => x.Value.Title == layoutSettingControl.Title); GlobalVar.dicLayout.TryRemove(item.Key, out _); } } this.Invalidate(); } private void btnTop_Click(object sender, EventArgs e) { bool isSelected = false; foreach (var control in pnlLayout.Controls) { if (control is LayoutSettingControl layoutSettingControl && layoutSettingControl.IsSelected) { if (isSelected) { MessageBox.Show("每次只能上移一个!", "异常"); return; } isSelected = true; } } for (int index = 0; index < GlobalVar.dicLayout.Count; index++) { foreach (var control in pnlLayout.Controls) { if (control is LayoutSettingControl layoutSettingControl && layoutSettingControl.IsSelected) { var item = GlobalVar.dicLayout.FirstOrDefault(x => x.Value.Title == layoutSettingControl.Title); int Key = item.Key; // 已经是第一个了,则无变化 if (Key == 0) { return; } var temp = GlobalVar.dicLayout[Key - 1]; GlobalVar.dicLayout[Key - 1] = item.Value; GlobalVar.dicLayout[Key] = temp; this.Invalidate(); return; } } } } } [Serializable] public class Layout { public string Title { get; set; } = "布局"; public string ProcessName { get; set; } = string.Empty; public string InputImage { get; set; } = string.Empty; public string SaveImageDir { get; set; } = string.Empty; public string SaveImageHead { get; set; } = string.Empty; public string RecordImage { get; set; } = string.Empty; public Layout() { } public Layout(string path) { SaveImageDir = path; } } }