示例#1
0
 public ParameterData(bool isSpinner, ShortGroupBox groupBox, NumericUpDown spinner, ComboBox comboBox)
 {
     this.IsSpinner = isSpinner;
     this.GroupBox  = groupBox;
     this.Spinner   = spinner;
     this.ComboBox  = comboBox;
 }
示例#2
0
        private void InitParameters()
        {
            _parameterDataList = new List <ParameterData>();
            ShortGroupBox[] groupBoxes = new ShortGroupBox[_commandData.MaxParameters];

            for (int index = 0; index < _commandData.MaxParameters; index++)
            {
                ShortGroupBox groupBox = new ShortGroupBox();
                groupBox.AutoSize = true;
                groupBox.Visible  = false;
                //flp_Parameters.Controls.Add(groupBox);

                NumericUpDown spinner = new NumericUpDown();
                spinner.Visible = false;

                ComboBox comboBox = new ComboBox();
                comboBox.Visible       = false;
                comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

                groupBox.Controls.Add(spinner);
                spinner.Location = new Point(5, 15);
                //spinner.Location = new Point((groupBox.Width - spinner.Width) / 2, 15);

                groupBox.Controls.Add(comboBox);
                comboBox.Location = spinner.Location;
                //comboBox.Location = new Point((groupBox.Width - comboBox.Width) / 2, 15);

                groupBoxes[index] = groupBox;
                _parameterDataList.Add(new ParameterData(true, groupBox, spinner, comboBox));

                //groupBox.Location = new Point(groupBox.Location.X, 0);
                //groupBox.Padding = new Padding(groupBox.Padding.Left, groupBox.Padding.Top, groupBox.Padding.Right, 0);
                //groupBox.Margin = new Padding(groupBox.Margin.Left, groupBox.Margin.Top, groupBox.Margin.Right, 0);
            }

            flp_Parameters.Controls.AddRange(groupBoxes);
        }
示例#3
0
        private void SetParameters(List <CommandParameter> parameters)
        {
            //flp_Parameters.Controls.Clear();
            ClearParameters();

            if ((parameters != null) && (parameters.Count > 0))
            {
                //List<Control> controls = new List<Control>();
                int index = 0;
                foreach (CommandParameter parameter in parameters)
                {
                    bool isHex    = parameter.Template.IsHex;
                    bool isSigned = parameter.Template.IsSigned;
                    int  range    = (1 << (parameter.Template.ByteLength << 3));

                    ParameterData parameterData = _parameterDataList[index];

                    //GroupBox groupBox = new GroupBox();
                    ShortGroupBox groupBox = parameterData.GroupBox;
                    NumericUpDown spinner  = parameterData.Spinner;
                    ComboBox      comboBox = parameterData.ComboBox;
                    //if (parameter.Template.Type == CommandParameterType.Number)
                    Dictionary <int, string> parameterValueMap = null;
                    //groupBox.AutoSize = true;

                    bool          hasParameterValueMap = _commandData.ParameterValueMaps.TryGetValue(parameter.Template.Type, out parameterValueMap);
                    List <string> entryNames           = hasParameterValueMap ? DataHelper.GetParameterEntryNames(parameter.Template, parameterValueMap) : null;

                    if ((!hasParameterValueMap) || (parameter.Value >= entryNames.Count))
                    {
                        parameterData.IsSpinner = true;
                        //NumericUpDown spinner = new NumericUpDown();
                        spinner.Width       = (parameter.GetByteLength() * 10) + 35;
                        spinner.Minimum     = isSigned ? (-(range / 2)) : 0;
                        spinner.Maximum     = isSigned ? ((range / 2) - 1) : (range - 1);
                        spinner.Hexadecimal = isHex;
                        spinner.Value       = (parameter.Value > spinner.Maximum) ? -(range - parameter.Value) : parameter.Value;
                        //spinner.Location = new Point((groupBox.Width - spinner.Width) / 2, 15);
                        //groupBox.Controls.Add(spinner);
                        spinner.Visible  = true;
                        comboBox.Visible = false;
                    }
                    else
                    {
                        parameterData.IsSpinner = false;
                        //ComboBox comboBox = new ComboBox();
                        //List<string> entryNames = DataHelper.GetParameterEntryNames(parameter.Template, parameterValueMap);
                        comboBox.Width = GetComboBoxWidth(comboBox, parameter.Template.Type, entryNames);

                        comboBox.Items.Clear();
                        comboBox.Items.AddRange(entryNames.ToArray());
                        //comboBox.Width = Math.Max(comboBox.Width, GetComboBoxWidth(comboBox, parameter.Template.Type, entryNames));
                        comboBox.SelectedIndex = parameter.Value;
                        //comboBox.Location = new Point((groupBox.Width - comboBox.Width) / 2, 15);
                        //groupBox.Controls.Add(comboBox);
                        comboBox.Visible = true;
                        spinner.Visible  = false;
                    }

                    string name = (parameter.Template.Name == "Unknown") ? "?" : parameter.Template.Name;
                    groupBox.Text = name + (isHex ? " (h)" : "");
                    //groupBox.AutoSize = true;
                    //controls.Add(groupBox);
                    //groupBox.Padding = new Padding(groupBox.Padding.Left, groupBox.Padding.Top, groupBox.Padding.Right, 0);
                    //groupBox.Margin = new Padding(groupBox.Margin.Left, groupBox.Margin.Top, groupBox.Margin.Right, 0);
                    //groupBox.AutoSize = false;
                    groupBox.Visible = true;

                    index++;
                }

                //flp_Parameters.Controls.AddRange(controls.ToArray());
            }
        }