视觉上位系统设计开发(halcon-winform)-2.全局变量设计

系统中会有很多数据需要执行流转,以及触发或者存储发送, 这里引入自定义的全局变量来完成这种需求,首先对全局变量数据对象进行设计。

/// <summary>
    /// 全局变量
    /// </summary>
    public class GlobalVariableModel
    {
        public VariableTypeEnum VariableType { set; get; }
        public string VariableName { set; get; }

        public object VariableValue { set; get; }
        public string Remark { set; get; }
    }

    public enum VariableTypeEnum
    {

        String = 0,
        Int = 1,
        Float = 2,
        Decimal = 3,
        Short = 4,
        Bool = 5
    }

包含数据类型、变量名称、变量值、备注。全局变量直接挂载在方案下面。一个方案的变量包含多个,因此是个List集合。

变量会贯穿每个节点 都可以使用,从节点触发 到节点执行后,以及数据结果关联都会用得到。

 

 维护的界面采用的是代码动态绘制panel 文本框 下拉框按钮等,自定义变量等等。代码如下

 private VariableControlModel AddTriggerControl()
        {
            FlowLayoutPanel triggerPanel = new FlowLayoutPanel();
            triggerPanel.BorderStyle = BorderStyle.FixedSingle;
            triggerPanel.FlowDirection = FlowDirection.LeftToRight;
            triggerPanel.Width = FlowPanelVariable.Width - 10;
            triggerPanel.Height = 42;
            Label variableLabel = new Label();
            variableLabel.Text = "变量";
            variableLabel.Height = triggerPanel.Height;
            variableLabel.AutoSize = false;
            variableLabel.Width = 50;
            variableLabel.TextAlign = ContentAlignment.MiddleRight;

            TextBox textBoxName = new TextBox();
            textBoxName.Width = 80;
            //类型
            Label variableTypeLabel = new Label();
            variableTypeLabel.Text = "类型";
            variableTypeLabel.Height = triggerPanel.Height;
            variableTypeLabel.AutoSize = false;
            variableTypeLabel.Width = 50;
            variableTypeLabel.TextAlign = ContentAlignment.MiddleRight;

            ComboBox comboBox = new ComboBox();
            comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBox.ValueMember = "Value";
            comboBox.DisplayMember = "Name";
            comboBox.Items.AddRange(typeList.ToArray());// (typeList.MapToList<VariableTypeModel>().ToArray());
            //comboBox.SelectedItem = item.Key;

            Label variableValueLabel = new Label();
            variableValueLabel.Text = "值";
            variableValueLabel.Height = triggerPanel.Height;
            variableValueLabel.TextAlign = ContentAlignment.MiddleRight;
            variableValueLabel.AutoSize = false;
            variableValueLabel.Width = 30;
            TextBox textBox = new TextBox();
            textBox.Width = 100;


            Label variableRemarkLabel = new Label();
            variableRemarkLabel.Text = "备注";
            variableRemarkLabel.Height = triggerPanel.Height;
            variableRemarkLabel.TextAlign = ContentAlignment.MiddleRight;
            variableRemarkLabel.AutoSize = false;
            variableRemarkLabel.Width = 50;
            TextBox textBoxRemark = new TextBox();
            textBoxRemark.Width = 250;

            Button button = new Button();
            button.Text = "移除";
            button.Width = 50;
            button.Height = 32;
            button.Click += Button_Click; ;

            //textBox.Text = item.Value;
            var model = new VariableControlModel()
            {
                FlowLayoutPanel = triggerPanel,
                VariableType = comboBox,
                VariableValueBox = textBox,
                VariableNameBox = textBoxName,
                VariableRemarkBox = textBoxRemark,
            };
            VariableControlModels.Add(model);
            triggerPanel.Controls.Add(variableLabel);
            triggerPanel.Controls.Add(textBoxName);
            triggerPanel.Controls.Add(variableTypeLabel);
            triggerPanel.Controls.Add(comboBox);
            triggerPanel.Controls.Add(variableValueLabel);
            triggerPanel.Controls.Add(textBox);
            triggerPanel.Controls.Add(variableRemarkLabel);
            triggerPanel.Controls.Add(textBoxRemark);

            triggerPanel.Controls.Add(button);


            FlowPanelVariable.Controls.Add(triggerPanel);
            return model;
        }

容器采用的是FlowPanel ,可以自动流式布局 控件添加到panel会自动往后追加,比较方便。

好了以上就是全局变量的设计思路。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

11eleven

你的鼓励是我创作的动力 !

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值