#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("GoalSeekingTarget View", "")] [Content(typeof(GoalParameter), true)] public partial class GoalSeekingTargetView : AsynchronousContentView { public new GoalParameter Content { get { return (GoalParameter)base.Content; } set { base.Content = value; } } public GoalSeekingTargetView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null) { groupBox.Text = Content.Name; goalTextBox.Text = Content.Goal.ToString(CultureInfo.CurrentCulture); weightTextBox.Text = Content.Weight.ToString(CultureInfo.CurrentCulture); varianceTextBox.Text = Content.Variance.ToString(CultureInfo.CurrentCulture); stepTextBox.Text = Content.Step.ToString(CultureInfo.CurrentCulture); activeCheckBox.Checked = Content.Active; Content.Changed += Content_Changed; } } private void Content_Changed(object sender, EventArgs args) { groupBox.Text = Content.Name; goalTextBox.Text = Content.Goal.ToString(CultureInfo.CurrentCulture); weightTextBox.Text = Content.Weight.ToString(CultureInfo.CurrentCulture); varianceTextBox.Text = Content.Variance.ToString(CultureInfo.CurrentCulture); stepTextBox.Text = Content.Step.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); } private void activeCheckBox_CheckedChanged(object sender, System.EventArgs e) { Content.Active = activeCheckBox.Checked; goalTextBox.Enabled = weightTextBox.Enabled = stepTextBox.Enabled = varianceTextBox.Enabled = Content.Active; } private void goalTextBox_TextChanged(object sender, EventArgs e) { double goal; if (double.TryParse(goalTextBox.Text, out goal)) Content.Goal = goal; } private void weightTextBox_TextChanged(object sender, EventArgs e) { double weight; if (double.TryParse(weightTextBox.Text, out weight)) Content.Weight = weight; } private void varianceTextBox_TextChanged(object sender, EventArgs e) { double variance; if (double.TryParse(varianceTextBox.Text, out variance)) Content.Variance = variance; } private void stepTextBox_TextChanged(object sender, System.EventArgs e) { double step; if (double.TryParse(stepTextBox.Text, out step)) Content.Step = step; } #endregion } }