#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.ComponentModel; using System.Globalization; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; namespace HeuristicLab.GoalSeeking.Views { [View("GoalSeekingParameter View", "")] [Content(typeof(InputParameter), true)] public partial class GoalSeekingParameterView : AsynchronousContentView { public new InputParameter Content { get { return (InputParameter)base.Content; } set { base.Content = value; } } public GoalSeekingParameterView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null) { groupBox.Text = Content.Name; minTextBox.Text = Content.Min.ToString(CultureInfo.CurrentCulture); maxTextBox.Text = Content.Max.ToString(CultureInfo.CurrentCulture); stepTextBox.Text = Content.Step.ToString(CultureInfo.CurrentCulture); valueTextBox.Text = Content.Value.ToString(CultureInfo.CurrentCulture); activeCheckBox.Checked = Content.Active; Content.Changed += Content_Changed; } } private void Content_Changed(object sender, EventArgs args) { groupBox.Text = Content.Name; minTextBox.Text = Content.Min.ToString(CultureInfo.CurrentCulture); maxTextBox.Text = Content.Max.ToString(CultureInfo.CurrentCulture); stepTextBox.Text = Content.Step.ToString(CultureInfo.CurrentCulture); valueTextBox.Text = Content.Value.ToString(CultureInfo.CurrentCulture); activeCheckBox.Checked = Content.Active; } #region event handlers private void TextBoxValidating(object sender, CancelEventArgs e) { double v; string errorMsg = "Could not parse the entered value. Please input a real number."; var tb = (TextBox)sender; if (!double.TryParse(tb.Text, out v)) { e.Cancel = true; tb.Select(0, tb.Text.Length); // Set the ErrorProvider error with the text to display. this.errorProvider.SetError(tb, errorMsg); errorProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink; errorProvider.SetIconPadding(tb, -20); } } private void TextBoxValidated(object sender, EventArgs e) { var tb = (TextBox)sender; errorProvider.SetError(tb, string.Empty); } #endregion private void minTextBox_TextChanged(object sender, EventArgs e) { double min; if (double.TryParse(minTextBox.Text, out min)) Content.Min = min; } private void maxTextBox_TextChanged(object sender, EventArgs e) { double max; if (double.TryParse(maxTextBox.Text, out max)) Content.Max = max; } private void stepTextBox_TextChanged(object sender, EventArgs e) { double step; if (double.TryParse(stepTextBox.Text, out step)) Content.Step = step; } private void valueTextBox_TextChanged(object sender, EventArgs e) { double value; if (double.TryParse(valueTextBox.Text, out value)) Content.Value = value; } private void activeCheckBox_CheckedChanged(object sender, EventArgs e) { Content.Active = activeCheckBox.Checked; minTextBox.Enabled = maxTextBox.Enabled = stepTextBox.Enabled = Content.Active; valueTextBox.Enabled = !Content.Active; } } }