private void UpdateAdjustmentControls(ImageAdjustmentType adjustmentType, Int32 adjustmentValue) { EnumControls(this.Controls); void EnumControls(IEnumerable controls) { foreach (Control control in controls) { var controlAdjustmentType = ImageAdjustmentTypeExtensions.ToImageAdjustmentType(control); if (controlAdjustmentType == adjustmentType) { if (control is TrackBar trackBar) { this.UpdateAdjustmentControl(() => trackBar.Value = adjustmentValue); } else if (control is NumericUpDown numericUpDown) { this.UpdateAdjustmentControl(() => numericUpDown.Value = adjustmentValue); } } if (control.HasChildren) { EnumControls(control.Controls); } } } }
private void OnAdjustmentControlValueChanged(Object sender, EventArgs e) { if (!this._adjustmentControlChangeCounter.IsZero()) { return; } var adjustmentControl = sender as Control; var adjustmentName = ImageAdjustmentTypeExtensions.ToImageAdjustmentType(adjustmentControl); if (ImageAdjustmentType.None == adjustmentName) { // TODO return; } var adjustmentValue = (adjustmentControl is TrackBar trackBar) ? trackBar.Value : ((adjustmentControl is NumericUpDown numericUpDown) ? (Int32)numericUpDown.Value : throw new Exception()); this.SetAdjustment(adjustmentName, 0, adjustmentValue); }