source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/NumericRangeControl.cs @ 17843

Last change on this file since 17843 was 17843, checked in by dpiringe, 7 weeks ago

#3026

  • removed property ConvertableType from all converters
  • removed the option to fixate or loosen the path of JsonItems (obsolete)
  • added a abstract formatter SymbolicRegressionSolutionFormatterBase as base formatter for ISymbolicRegressionSolution
  • unified the construction of exporter controls
  • code cleanup
File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using System.Globalization;
11
12namespace HeuristicLab.JsonInterface.OptimizerIntegration {
13  public partial class NumericRangeControl : UserControl {
14    public TextBox TBMinRange { get; set; }
15    public TextBox TBMaxRange { get; set; }
16    public CheckBox EnableMinRange { get; set; }
17    public CheckBox EnableMaxRange { get; set; }
18
19    private NumericRangeControl() {
20      InitializeComponent();
21      Init();
22    }
23
24    protected NumericRangeControl(IJsonItemVM vm) {
25      InitializeComponent();
26      Init();
27      TBMinRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MinRange));
28      TBMaxRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MaxRange));
29      EnableMinRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMinRange),
30        false, DataSourceUpdateMode.OnPropertyChanged);
31      EnableMaxRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMaxRange),
32        false, DataSourceUpdateMode.OnPropertyChanged);
33    }
34
35
36    private void Init() {
37      TBMinRange = textBoxFrom;
38      TBMaxRange = textBoxTo;
39      EnableMinRange = checkBoxFrom;
40      EnableMaxRange = checkBoxTo;
41      checkBoxFrom.CheckedChanged += ToggleFromInput;
42      checkBoxTo.CheckedChanged += ToggleToInput;
43    }
44
45    private void ToggleToInput(object sender, EventArgs e) {
46      textBoxTo.ReadOnly = !checkBoxTo.Checked;
47    }
48
49    private void ToggleFromInput(object sender, EventArgs e) {
50      textBoxFrom.ReadOnly = !checkBoxFrom.Checked;
51    }
52
53    private void textBoxFrom_Validating(object sender, CancelEventArgs e) {
54      if (string.IsNullOrWhiteSpace(textBoxFrom.Text)) {
55        errorProvider.SetError(textBoxFrom, "'From' must not be empty.");
56        e.Cancel = true;
57      } else {
58        errorProvider.SetError(textBoxFrom, null);
59      }
60    }
61
62    private void textBoxTo_Validating(object sender, CancelEventArgs e) {
63      if (string.IsNullOrWhiteSpace(textBoxTo.Text)) {
64        errorProvider.SetError(textBoxTo, "'To' must not be empty.");
65        e.Cancel = true;
66      } else {
67        errorProvider.SetError(textBoxTo, null);
68      }
69    }
70
71    public static UserControl Create(IJsonItemVM vm) => new NumericRangeControl(vm);
72  }
73}
Note: See TracBrowser for help on using the repository browser.