Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3138_Shape_Constraints_Transformations/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonFloatFilterView.cs @ 18180

Last change on this file since 18180 was 18180, checked in by dpiringe, 2 years ago

#3138

  • merged trunk into branch
File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Windows.Forms;
23using HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
25
26namespace HeuristicLab.Clients.OKB.Query {
27  [View("OrdinalComparisonFloatFilter View")]
28  [Content(typeof(OrdinalComparisonFloatFilter), true)]
29  public partial class OrdinalComparisonFloatFilterView : OrdinalComparisonFilterView {
30    public new OrdinalComparisonFloatFilter Content {
31      get { return (OrdinalComparisonFloatFilter)base.Content; }
32      set { base.Content = value; }
33    }
34
35    public OrdinalComparisonFloatFilterView() {
36      InitializeComponent();
37      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
38      errorProvider.SetIconPadding(valueTextBox, 2);
39    }
40
41    protected override void OnContentChanged() {
42      base.OnContentChanged();
43      valueTextBox.Text = Content == null ? string.Empty : Content.Value.ToString();
44    }
45
46    protected override void SetEnabledStateOfControls() {
47      base.SetEnabledStateOfControls();
48      valueTextBox.Enabled = Content != null;
49      valueTextBox.ReadOnly = ReadOnly;
50    }
51
52    private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
53      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) {
54        label.Focus();  // set focus on label to validate data
55        e.SuppressKeyPress = true;
56      } else if (e.KeyCode == Keys.Escape) {
57        valueTextBox.Text = Content.Value.ToString();
58        label.Focus();  // set focus on label to validate data
59        e.SuppressKeyPress = true;
60      }
61    }
62    private void valueTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
63      float val;
64      if (!float.TryParse(valueTextBox.Text, out val)) {
65        e.Cancel = true;
66        errorProvider.SetError(valueTextBox, "Invalid Float Value");
67        valueTextBox.SelectAll();
68      }
69    }
70    private void valueTextBox_Validated(object sender, System.EventArgs e) {
71      if (Content != null) {
72        Content.Value = float.Parse(valueTextBox.Text);
73        errorProvider.SetError(valueTextBox, string.Empty);
74      }
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.