Example #1
0
        private void ReadControl(Control c)
        {
            var tag = c.Tag;

            if (tag is string strTag)
            {
                var prop = optionPage.GetType().GetProperty(strTag);
                if (prop != null)
                {
                    var val = prop.GetValue(optionPage);
                    if (c is CheckBox cb && val is bool bValue)
                    {
                        cb.Checked = bValue;
                    }
                    if (c is NumericUpDown number && val is int iValue)
                    {
                        number.Value = iValue >= number.Minimum && iValue < number.Maximum ? iValue : number.Minimum;
                    }
                    if (c is TextBox tb)
                    {
                        tb.Text = val.ToString();
                    }
                }
            }
            foreach (Control control in c.Controls)
            {
                ReadControl(control);
            }
        }