summaryrefslogtreecommitdiff
path: root/grapher/Field.cs
diff options
context:
space:
mode:
Diffstat (limited to 'grapher/Field.cs')
-rw-r--r--grapher/Field.cs49
1 files changed, 29 insertions, 20 deletions
diff --git a/grapher/Field.cs b/grapher/Field.cs
index 5ef057d..d34472b 100644
--- a/grapher/Field.cs
+++ b/grapher/Field.cs
@@ -10,6 +10,12 @@ namespace grapher
{
public class Field
{
+ #region Constants
+
+ public const string DefaultFormatString = "#.#########";
+
+ #endregion Constants
+
#region Enums
public enum FieldState
@@ -34,6 +40,7 @@ namespace grapher
DefaultData = defaultData;
State = FieldState.Undefined;
ContainingForm = containingForm;
+ FormatString = DefaultFormatString;
box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown);
box.Leave += new System.EventHandler(FocusLeave);
@@ -50,6 +57,8 @@ namespace grapher
public double Data { get; private set; }
+ public string FormatString { get; set; }
+
public string DefaultText { get; }
public FieldState State { get; private set; }
@@ -163,15 +172,8 @@ namespace grapher
{
if (State == FieldState.Typing)
{
- if (PreviousState == FieldState.Default)
- {
- SetToDefault();
- }
- else if (PreviousState == FieldState.Entered)
- {
- SetToEntered();
- Box.Text = DecimalString(Data);
- }
+ TextToData();
+ SetToEntered();
}
}
@@ -179,15 +181,8 @@ namespace grapher
{
if (e.KeyCode == Keys.Enter)
{
- try
- {
- Data = Convert.ToDouble(((TextBox)sender).Text);
- }
- catch
- {
- }
-
- Box.Text = DecimalString(Data);
+ TextToData();
+
e.Handled = true;
e.SuppressKeyPress = true;
@@ -201,11 +196,25 @@ namespace grapher
}
}
- private static string DecimalString(double value)
+ private void TextToData()
+ {
+ try
+ {
+ Data = Convert.ToDouble(Box.Text);
+ }
+ catch
+ {
+ }
+
+ Box.Text = DecimalString(Data);
+ }
+
+ private string DecimalString(double value)
{
- return value.ToString("N2");
+ return value.ToString(FormatString);
}
+
#endregion Methods
}
}