Changeset 6109


Ignore:
Timestamp:
05/03/11 16:55:56 (10 years ago)
Author:
gkronber
Message:

#1505 changed input validation in SymbolView.

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.Designer.cs

    r5832 r6109  
    8080      this.initialFrequencyTextBox.Size = new System.Drawing.Size(227, 20);
    8181      this.initialFrequencyTextBox.TabIndex = 4;
    82       this.initialFrequencyTextBox.TextChanged += new System.EventHandler(this.initialFrequencyTextBox_TextChanged);
     82      this.initialFrequencyTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.initialFrequencyTextBox_KeyDown);
     83      this.initialFrequencyTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.initialFrequencyTextBox_Validating);
     84      this.initialFrequencyTextBox.Validated += new System.EventHandler(this.initialFrequencyTextBox_Validated);
    8385      //
    8486      // SymbolView
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs

    r5809 r6109  
    2525using HeuristicLab.MainForm;
    2626using HeuristicLab.MainForm.WindowsForms;
     27using System.ComponentModel;
    2728
    2829namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    6768
    6869    #region control event handlers
    69     private void initialFrequencyTextBox_TextChanged(object sender, EventArgs e) {
     70    private void initialFrequencyTextBox_KeyDown(object sender, KeyEventArgs e) {
     71      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
     72        initialFrequencyLabel.Select();  // select label to validate data
     73
     74      if (e.KeyCode == Keys.Escape) {
     75        initialFrequencyTextBox.Text = Content.InitialFrequency.ToString();
     76        initialFrequencyLabel.Select();  // select label to validate data
     77      }
     78    }
     79    private void initialFrequencyTextBox_Validating(object sender, CancelEventArgs e) {
     80      double freq;
     81      if (double.TryParse(initialFrequencyTextBox.Text, out freq) && freq >= 0.0) {
     82        errorProvider.SetError(initialFrequencyTextBox, string.Empty);
     83        e.Cancel = false;
     84      } else {
     85        errorProvider.SetError(initialFrequencyTextBox, "Invalid value");
     86        e.Cancel = true;
     87      }
     88    }
     89    private void initialFrequencyTextBox_Validated(object sender, EventArgs e) {
    7090      double freq;
    7191      if (double.TryParse(initialFrequencyTextBox.Text, out freq) && freq >= 0.0) {
    7292        Content.InitialFrequency = freq;
    73         errorProvider.SetError(initialFrequencyTextBox, string.Empty);
    74       } else {
    75         errorProvider.SetError(initialFrequencyTextBox, "Invalid value");
    76       }
     93      }
    7794    }
    7895    #endregion
Note: See TracChangeset for help on using the changeset viewer.