コード例 #1
0
ファイル: MainClass.cs プロジェクト: McRayJason/TDHelper
        /// <summary>
        /// Validate the setting value.
        /// </summary>
        /// <param name="propertyName">The name of the setting property.</param>
        /// <param name="control">The associated control.</param>
        /// <param name="settings">The settings object.</param>
        private void ValidateSettingValue(
            string propertyName,
            NumericUpDown control,
            TDSettings settings,
            decimal defaultValue = -1)
        {
            // retrieve the value from the settings object.
            PropertyInfo prop = settings.GetType().GetProperty(propertyName);

            decimal value    = (decimal)prop.GetValue(settings);
            decimal newValue = value;

            // Compare with the control limits and set a new value if outside those limits.
            if (value < control.Minimum)
            {
                newValue
                    = defaultValue == -1
                    ? control.Minimum
                    : defaultValue;
            }
            else if (value > control.Maximum)
            {
                newValue = control.Maximum;
            }

            // Change the value if required.
            if (newValue != value)
            {
                prop.SetValue(settings, newValue);
            }
        }
コード例 #2
0
ファイル: MainClass.cs プロジェクト: McRayJason/TDHelper
        /// <summary>
        /// Validate the control value. Write the updated value back to the settings object.
        /// </summary>
        /// <param name="propertyName">The name of the setting property.</param>
        /// <param name="control">The associated control.</param>
        /// <param name="settings">The settings object.</param>
        private void ValidateControlValue(
            string propertyName,
            NumericUpDown control,
            TDSettings settings)
        {
            decimal value    = control.Value;
            decimal newValue = value;

            // Compare with the control limits and set a new value if outside those limits.
            if (value < control.Minimum)
            {
                newValue = control.Minimum;
            }
            else if (value > control.Maximum)
            {
                newValue = control.Maximum;
            }

            // Change the value if required.
            if (newValue != value)
            {
                control.Value = newValue;

                PropertyInfo prop = settings.GetType().GetProperty(propertyName);

                prop.SetValue(settings, newValue);
            }
        }