Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleValueView.cs @ 3155

Last change on this file since 3155 was 3048, checked in by swagner, 15 years ago

Renamed classes of HeuristicLab.Data (#909)

File size: 3.6 KB
RevLine 
[2665]1#region License Information
2/* HeuristicLab
[2790]3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2665]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.ComponentModel;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
[2713]26using HeuristicLab.MainForm.WindowsForms;
[2665]27
28namespace HeuristicLab.Data.Views {
[3048]29  [View("StringConvertibleValue View")]
30  [Content(typeof(IStringConvertibleValue), true)]
31  public partial class StringConvertibleValueView : ContentView {
32    public new IStringConvertibleValue Content {
33      get { return (IStringConvertibleValue)base.Content; }
[2713]34      set { base.Content = value; }
[2665]35    }
36
[3048]37    public StringConvertibleValueView() {
[2665]38      InitializeComponent();
[3048]39      Caption = "StringConvertibleValue View";
[2676]40      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
41      errorProvider.SetIconPadding(valueTextBox, 2);
[2665]42    }
[3048]43    public StringConvertibleValueView(IStringConvertibleValue content)
[2665]44      : this() {
[2727]45      Content = content;
[2665]46    }
47
[2713]48    protected override void DeregisterContentEvents() {
[2932]49      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
[2713]50      base.DeregisterContentEvents();
[2665]51    }
52
[2713]53    protected override void RegisterContentEvents() {
54      base.RegisterContentEvents();
[2932]55      Content.ValueChanged += new EventHandler(Content_ValueChanged);
[2665]56    }
57
[2713]58    protected override void OnContentChanged() {
59      base.OnContentChanged();
60      if (Content == null) {
[3048]61        Caption = "StringConvertibleValue View";
[2669]62        valueTextBox.Text = string.Empty;
[2665]63        valueTextBox.Enabled = false;
64      } else {
[2713]65        Caption = Content.GetValue() + " (" + Content.GetType().Name + ")";
66        valueTextBox.Text = Content.GetValue();
[2665]67        valueTextBox.Enabled = true;
68      }
69    }
70
[2932]71    private void Content_ValueChanged(object sender, EventArgs e) {
[2665]72      if (InvokeRequired)
[2932]73        Invoke(new EventHandler(Content_ValueChanged), sender, e);
[2665]74      else
[2713]75        valueTextBox.Text = Content.GetValue();
[2665]76    }
77
[2676]78    private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
79      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
80        valueLabel.Focus();  // set focus on label to validate data
81      if (e.KeyCode == Keys.Escape) {
[2713]82        valueTextBox.Text = Content.GetValue();
[2676]83        valueLabel.Focus();  // set focus on label to validate data
84      }
85    }
[2665]86    private void valueTextBox_Validating(object sender, CancelEventArgs e) {
[2694]87      string errorMessage;
[2713]88      if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
[2676]89        e.Cancel = true;
[2694]90        errorProvider.SetError(valueTextBox, errorMessage);
[2665]91        valueTextBox.SelectAll();
92      }
93    }
94    private void valueTextBox_Validated(object sender, EventArgs e) {
[2713]95      Content.SetValue(valueTextBox.Text);
[2676]96      errorProvider.SetError(valueTextBox, string.Empty);
[2665]97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.