Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonDateTimeFilterView.cs @ 18166

Last change on this file since 18166 was 18166, checked in by gkronber, 2 years ago

#3047: set SuppressKeyPress=true in all controls that handle the Enter key explicitly (except for dialogs).

File size: 3.0 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;
23using System.Windows.Forms;
24using HeuristicLab.MainForm;
25using HeuristicLab.MainForm.WindowsForms;
26
27namespace HeuristicLab.Clients.OKB.Query {
28  [View("OrdinalComparisonDateTimeFilter View")]
29  [Content(typeof(OrdinalComparisonDateTimeFilter), true)]
30  public partial class OrdinalComparisonDateTimeFilterView : OrdinalComparisonFilterView {
31    public new OrdinalComparisonDateTimeFilter Content {
32      get { return (OrdinalComparisonDateTimeFilter)base.Content; }
33      set { base.Content = value; }
34    }
35
36    public OrdinalComparisonDateTimeFilterView() {
37      InitializeComponent();
38      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
39      errorProvider.SetIconPadding(valueTextBox, 2);
40    }
41
42    protected override void OnContentChanged() {
43      base.OnContentChanged();
44      valueTextBox.Text = Content == null ? string.Empty : Content.Value.ToString();
45    }
46
47    protected override void SetEnabledStateOfControls() {
48      base.SetEnabledStateOfControls();
49      valueTextBox.Enabled = Content != null;
50      valueTextBox.ReadOnly = ReadOnly;
51    }
52
53    private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
54      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) {
55        label.Focus();  // set focus on label to validate data
56        e.SuppressKeyPress = true;
57      } else if (e.KeyCode == Keys.Escape) {
58        valueTextBox.Text = Content.Value.ToString();
59        label.Focus();  // set focus on label to validate data
60        e.SuppressKeyPress = true;
61      }
62    }
63    private void valueTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
64      DateTime val;
65      if (!DateTime.TryParse(valueTextBox.Text, out val)) {
66        e.Cancel = true;
67        errorProvider.SetError(valueTextBox, "Invalid DateTime Value");
68        valueTextBox.SelectAll();
69      }
70    }
71    private void valueTextBox_Validated(object sender, System.EventArgs e) {
72      if (Content != null) {
73        Content.Value = DateTime.Parse(valueTextBox.Text);
74        errorProvider.SetError(valueTextBox, string.Empty);
75      }
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.