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
namespace LB_VisionFlowNode
{
    public partial class FlowNodeEditor : UserControl
    {
        public FlowNodeEditor()
        {
            InitializeComponent();
        }
 
        private void btn_Run_Click(object sender, EventArgs e)
        {
            pnl_Main.Run(out _);
        }
 
        private void btn_Clear_Click(object sender, EventArgs e)
        {
            pnl_Main.ClearNodes();
        }
 
        private void btn_Load_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                // 设置文件对话框的属性
                openFileDialog.Multiselect = false; // 不允许多选
                                                    // 设置文件过滤器,支持多种文件类型
                openFileDialog.Filter = "Ini Files (*.json)|*.json|All Files (*.*)|*.*";
                // 显示文件对话框
                DialogResult result = openFileDialog.ShowDialog();
 
                // 处理对话框返回结果
                if (result == DialogResult.OK)
                {
                    // 获取用户选择的文件名
                    string[] selectedFiles = openFileDialog.FileNames;
                    if (selectedFiles.Length > 0)
                        pnl_Main.Load(selectedFiles[0]);
                }
            }
        }
 
        private void btn_Save_Click(object sender, EventArgs e)
        {
            // 创建 SaveFileDialog 实例
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                // 设置对话框标题
                saveFileDialog.Title = "保存文件";
 
                // 设置默认路径
                saveFileDialog.InitialDirectory = Application.StartupPath;
 
                // 设置文件类型过滤器
                saveFileDialog.Filter = "文本文件 (*.json)|*.json|所有文件 (*.*)|*.*";
 
                // 设置默认文件名
                saveFileDialog.FileName = "panel.json";
 
                // 显示对话框并检查用户是否点击了保存按钮
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    // 获取用户选择的文件路径
                    string fullPath = saveFileDialog.FileName;
                    pnl_Main.Save(fullPath);
                }
            }
 
 
        }
    }
}