Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/20/16 13:01:24 (8 years ago)
Author:
pfleck
Message:

#2597

  • Added validation in GradientChartConfigurationDialog and DensityTrackbar.
  • Added optional configuration button for GradientChart.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChartConfigurationDialog.cs

    r13853 r13855  
    2121
    2222using System;
     23using System.ComponentModel;
    2324using System.Globalization;
    2425using System.Windows.Forms;
     
    2829  public partial class GradientChartConfigurationDialog : Form {
    2930    private readonly GradientChart chart;
    30 
    31     private IFormatProvider FormatProvider {
    32       get { return CultureInfo.CurrentUICulture.NumberFormat; }
    33     }
    3431
    3532    public GradientChartConfigurationDialog(GradientChart chart) {
     
    4138      if (chart.FixedXAxisMin.HasValue && chart.FixedXAxisMax.HasValue) {
    4239        xAutomaticCheckBox.Checked = false;
    43         minXTextBox.Text = chart.FixedXAxisMin.Value.ToString(FormatProvider);
    44         maxXTextBox.Text = chart.FixedXAxisMax.Value.ToString(FormatProvider);
     40        minXTextBox.Text = chart.FixedXAxisMin.Value.ToString(CultureInfo.CurrentUICulture);
     41        maxXTextBox.Text = chart.FixedXAxisMax.Value.ToString(CultureInfo.CurrentUICulture);
    4542      } else xAutomaticCheckBox.Checked = true;
    4643      if (chart.FixedYAxisMin.HasValue && chart.FixedYAxisMax.HasValue) {
    4744        yAutomaticCheckBox.Checked = false;
    48         minYTextBox.Text = chart.FixedYAxisMin.Value.ToString(FormatProvider);
    49         maxYTextBox.Text = chart.FixedYAxisMax.Value.ToString(FormatProvider);
     45        minYTextBox.Text = chart.FixedYAxisMin.Value.ToString(CultureInfo.CurrentUICulture);
     46        maxYTextBox.Text = chart.FixedYAxisMax.Value.ToString(CultureInfo.CurrentUICulture);
    5047      } else yAutomaticCheckBox.Checked = true;
    5148      StepsNumericUpDown.Value = chart.DrawingSteps;
     
    5956          chart.FixedXAxisMax = null;
    6057        } else {
    61           var min = Convert.ToDouble(minXTextBox.Text, FormatProvider);
    62           var max = Convert.ToDouble(maxXTextBox.Text, FormatProvider);
     58          var min = double.Parse(minXTextBox.Text, CultureInfo.CurrentUICulture);
     59          var max = double.Parse(maxXTextBox.Text, CultureInfo.CurrentUICulture);
    6360          chart.FixedXAxisMin = min;
    6461          chart.FixedXAxisMax = max;
     
    6966          chart.FixedYAxisMax = null;
    7067        } else {
    71           var min = Convert.ToDouble(minYTextBox.Text, FormatProvider);
    72           var max = Convert.ToDouble(maxYTextBox.Text, FormatProvider);
     68          var min = double.Parse(minYTextBox.Text, CultureInfo.CurrentUICulture);
     69          var max = double.Parse(maxYTextBox.Text, CultureInfo.CurrentUICulture);
    7370          chart.FixedYAxisMin = min;
    7471          chart.FixedYAxisMax = max;
     
    8178        Close();
    8279      }
    83       catch (FormatException fe) {
    84         MessageBox.Show(this, "Illegal number format: {0}", fe.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
     80      catch (FormatException) {
     81        MessageBox.Show(this, "Illegal number format", "Wrong format", MessageBoxButtons.OK, MessageBoxIcon.Error);
    8582      }
    8683      finally {
     
    9693      maxYTextBox.Enabled = !yAutomaticCheckBox.Checked;
    9794    }
     95
     96    private void numberTextBox_Validating(object sender, CancelEventArgs e) {
     97      var textBox = sender as TextBox;
     98      if (textBox != null) {
     99        double number;
     100        if (!double.TryParse(textBox.Text, NumberStyles.Any, CultureInfo.CurrentUICulture, out number)) {
     101          e.Cancel = true;
     102          applyButton.Enabled = false;
     103          errorProvider.SetIconAlignment(textBox, ErrorIconAlignment.MiddleLeft);
     104          errorProvider.SetIconPadding(textBox, 2);
     105          errorProvider.SetError(textBox, "Illegal number format");
     106          textBox.SelectAll();
     107        }
     108      }
     109    }
     110
     111    private void numberTextBox_Validated(object sender, EventArgs e) {
     112      var textBox = sender as TextBox;
     113      if (textBox != null) {
     114        errorProvider.SetError(textBox, string.Empty);
     115        applyButton.Enabled = true;
     116      }
     117    }
    98118  }
    99119}
Note: See TracChangeset for help on using the changeset viewer.