C3204
2025-12-18 d85cbf0ccd61d95b96695756e0c90db8b7679545
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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();
 
            btn_Save.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++)
            {
                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);
            }
        }
 
        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 ImageTitle { get; set; } = string.Empty;
 
        public string RecordImage1 { get; set; } = string.Empty;
 
        public string RecordImage2 { get; set; } = string.Empty;
 
        public string RecordImage3 { get; set; } = string.Empty;
 
        public Layout() { }
 
        public Layout(string path) { SaveImageDir = path; }
 
    }
}