コード例 #1
0
        private void FillOptions()
        {
            var list = new DevOptions();
            var row  = 0;

            OptionPanel.Controls.Clear();
            foreach (var option in list)
            {
                var lbl = new Label()
                {
                    AutoSize = true, TextAlign = ContentAlignment.MiddleLeft
                };

                switch (option.Type)
                {
                case "System.Boolean":
                    var chk = new CheckBox()
                    {
                        Text      = option.Label,
                        Checked   = Boolean.Parse(option.Recommend),
                        Tag       = new string[] { option.Area, option.Name },
                        AutoSize  = true,
                        TextAlign = ContentAlignment.MiddleLeft
                    };
                    toolTip1.SetToolTip(chk, option.Desc);
                    OptionPanel.Controls.Add(lbl);
                    OptionPanel.Controls.Add(chk);
                    OptionPanel.SetRow(lbl, row);
                    OptionPanel.SetColumn(lbl, 0);
                    OptionPanel.SetRow(chk, row);
                    OptionPanel.SetColumn(chk, 1);
                    break;

                case "System.Int32":
                    var num = new NumericUpDown()
                    {
                        Value    = int.Parse(option.Recommend),
                        Tag      = new string[] { option.Area, option.Name },
                        AutoSize = true,
                    };
                    toolTip1.SetToolTip(num, option.Desc);
                    lbl.Text = option.Label;
                    OptionPanel.Controls.Add(lbl);
                    OptionPanel.Controls.Add(num);
                    OptionPanel.SetRow(lbl, row);
                    OptionPanel.SetColumn(lbl, 0);
                    OptionPanel.SetRow(num, row);
                    OptionPanel.SetColumn(num, 1);
                    break;

                default:
                    break;
                }

                row += 1;
                OptionPanel.RowCount = row;
            }
        }
コード例 #2
0
        private DevOptions GetOptions()
        {
            var retVal = new DevOptions();

            System.Diagnostics.Debug.WriteLine(OptionPanel.Controls.Count);
            foreach (Control control in OptionPanel.Controls)
            {
                var type = control.GetType().ToString();
                if (control.Tag != null)
                {
                    System.Diagnostics.Debug.WriteLine(type + ":" + string.Join(",", ((string[])control.Tag)));
                }
                DevOption item;
                switch (type)
                {
                case "System.Windows.Forms.CheckBox":
                    var chk = (CheckBox)control;
                    item       = retVal.First(f => f.Name == ((string[])chk.Tag)[1]);
                    item.Value = chk.Checked.ToString();
                    System.Diagnostics.Debug.WriteLine(item.Name + ":" + chk.Checked.ToString());
                    retVal.Add(item);
                    break;

                case "System.Windows.Forms.NumericUpDown":
                    var num = (NumericUpDown)control;
                    item       = retVal.First(f => f.Name == ((string[])num.Tag)[1]);
                    item.Value = num.Value.ToString();
                    System.Diagnostics.Debug.WriteLine(item.Name + ":" + num.Value.ToString());
                    retVal.Add(item);
                    break;

                default:
                    System.Diagnostics.Debug.WriteLine(control.Name + ":" + type + ":" + control.Tag?.ToString());
                    break;
                }
            }
            return(retVal);
        }