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

Last change on this file since 17829 was 17829, checked in by dpiringe, 2 months ago

#3026

  • moved JsonItems from Models to JsonItems
  • moved WinForms controls from Shared to Views
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    public NumericRangeControl() {
19      InitializeComponent();
20      TBMinRange = textBoxFrom;
21      TBMaxRange = textBoxTo;
22      EnableMinRange = checkBoxFrom;
23      EnableMaxRange = checkBoxTo;
24      checkBoxFrom.CheckedChanged += ToggleFromInput;
25      checkBoxTo.CheckedChanged += ToggleToInput;
26    }
27
28    private void ToggleToInput(object sender, EventArgs e) {
29      textBoxTo.ReadOnly = !checkBoxTo.Checked;
30    }
31
32    private void ToggleFromInput(object sender, EventArgs e) {
33      textBoxFrom.ReadOnly = !checkBoxFrom.Checked;
34    }
35
36    private void textBoxFrom_Validating(object sender, CancelEventArgs e) {
37      if (string.IsNullOrWhiteSpace(textBoxFrom.Text)) {
38        errorProvider.SetError(textBoxFrom, "'From' must not be empty.");
39        e.Cancel = true;
40      } else {
41        errorProvider.SetError(textBoxFrom, null);
42      }
43    }
44
45    private void textBoxTo_Validating(object sender, CancelEventArgs e) {
46      if (string.IsNullOrWhiteSpace(textBoxTo.Text)) {
47        errorProvider.SetError(textBoxTo, "'To' must not be empty.");
48        e.Cancel = true;
49      } else {
50        errorProvider.SetError(textBoxTo, null);
51      }
52    }
53
54    public static UserControl Create(IJsonItemVM vm) {
55      NumericRangeControl numericRangeControl = new NumericRangeControl();
56      numericRangeControl.TBMinRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MinRange));
57      numericRangeControl.TBMaxRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MaxRange));
58      numericRangeControl.EnableMinRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMinRange),
59        false, DataSourceUpdateMode.OnPropertyChanged);
60      numericRangeControl.EnableMaxRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMaxRange),
61        false, DataSourceUpdateMode.OnPropertyChanged);
62      return numericRangeControl;
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.