diff --git a/source/Demo/UpDownDemoLib/Views/ByteUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/ByteUpDownDemo.xaml
index 94d5309..457d027 100644
--- a/source/Demo/UpDownDemoLib/Views/ByteUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/ByteUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
MouseWheelAccelaratorKey="{Binding AccelModifierKey, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
diff --git a/source/Demo/UpDownDemoLib/Views/DecimalUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/DecimalUpDownDemo.xaml
index c03339d..54db41f 100644
--- a/source/Demo/UpDownDemoLib/Views/DecimalUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/DecimalUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/DoubleUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/DoubleUpDownDemo.xaml
index d39491b..4ce41bf 100644
--- a/source/Demo/UpDownDemoLib/Views/DoubleUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/DoubleUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/FloatUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/FloatUpDownDemo.xaml
index 141a2a2..3a463a8 100644
--- a/source/Demo/UpDownDemoLib/Views/FloatUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/FloatUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/LongUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/LongUpDownDemo.xaml
index 7a4f425..54a39f0 100644
--- a/source/Demo/UpDownDemoLib/Views/LongUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/LongUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/NumericUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/NumericUpDownDemo.xaml
index 1d45b74..22d6115 100644
--- a/source/Demo/UpDownDemoLib/Views/NumericUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/NumericUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/PercentageUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/PercentageUpDownDemo.xaml
index 44e9f27..6ddb58a 100644
--- a/source/Demo/UpDownDemoLib/Views/PercentageUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/PercentageUpDownDemo.xaml
@@ -40,6 +40,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue, Converter={StaticResource FactorToDoubleConverter}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MinValue="{Binding MinimumValue, Converter={StaticResource FactorToDoubleConverter}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
diff --git a/source/Demo/UpDownDemoLib/Views/SByteUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/SByteUpDownDemo.xaml
index a286d69..b872464 100644
--- a/source/Demo/UpDownDemoLib/Views/SByteUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/SByteUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/ShortUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/ShortUpDownDemo.xaml
index 19377a1..540d351 100644
--- a/source/Demo/UpDownDemoLib/Views/ShortUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/ShortUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/UIntegerUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/UIntegerUpDownDemo.xaml
index c27aef9..4957aef 100644
--- a/source/Demo/UpDownDemoLib/Views/UIntegerUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/UIntegerUpDownDemo.xaml
@@ -36,6 +36,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/ULongUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/ULongUpDownDemo.xaml
index 29bf9d7..672d2b5 100644
--- a/source/Demo/UpDownDemoLib/Views/ULongUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/ULongUpDownDemo.xaml
@@ -35,6 +35,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/Demo/UpDownDemoLib/Views/UShortUpDownDemo.xaml b/source/Demo/UpDownDemoLib/Views/UShortUpDownDemo.xaml
index 2484175..b575d87 100644
--- a/source/Demo/UpDownDemoLib/Views/UShortUpDownDemo.xaml
+++ b/source/Demo/UpDownDemoLib/Views/UShortUpDownDemo.xaml
@@ -34,6 +34,7 @@
IsDisplayLengthFixed="True"
IsMouseDragEnabled="{Binding ElementName=IsMouseDragEnabledCheckBox, Path=IsChecked}"
IsReadOnly="False"
+ IsUpdateValueWhenLostFocus="True"
LargeStepSize="{Binding LargeStepSize, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
MaxValue="{Binding MaximumValue}"
MinValue="{Binding MinimumValue}"
diff --git a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs
index b07f652..1e82c4d 100644
--- a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs
+++ b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs
@@ -3,6 +3,7 @@ namespace NumericUpDownLib.Base
using NumericUpDownLib.Enums;
using NumericUpDownLib.Models;
using System;
+ using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@@ -1159,21 +1160,44 @@ protected string FormatNumber(T number)
}
///
- /// Checks if the current string entered in the textbox is:
- /// 1) A valid number (syntax)
- /// 2) within bounds (Min <= number <= Max )
- ///
- /// 3) adjusts the string if it appears to be invalid and
- ///
- /// 4) true:
- /// Applies the FormatString property to format the text in a certain way
- ///
- ///
- ///
- /// the value of the string with special format
- protected abstract T FormatText(string text, bool formatNumber = true);
+ /// Checks if the current string entered in the textbox is:
+ /// 1) A valid number (syntax)
+ /// 2) within bounds (Min <= number <= Max )
+ ///
+ /// 3) adjusts the string if it appears to be invalid and
+ ///
+ /// 4) true:
+ /// Applies the FormatString property to format the text in a certain way
+ ///
+ ///
+ ///
+ /// the value of the string with special format
+ protected T FormatText(string text, bool formatNumber = true)
+ {
+ if (_PART_TextBox == null)
+ return Value;
- ///
+ T number = default;
+ // Does this text represent a valid number ?
+ if (ParseText(text, out number))
+ {
+ number = CoerceValue(number);
+
+ _PART_TextBox.Text = FormatNumber(number);
+ _PART_TextBox.SelectionStart = 0;
+
+ return number;
+ }
+
+ // Reset to last value since string does not appear to represent a number
+ _PART_TextBox.SelectionStart = 0;
+ _PART_TextBox.Text = FormatNumber(Value);
+ return LastEditingNumericValue;
+ }
+
+ protected abstract bool ParseText(string text, out T number);
+
+ ///
/// Verify the text is valid or not while use is typing
///
///
diff --git a/source/NumericUpDownLib/ByteUpDown.cs b/source/NumericUpDownLib/ByteUpDown.cs
index d32a2b0..2fe4e77 100644
--- a/source/NumericUpDownLib/ByteUpDown.cs
+++ b/source/NumericUpDownLib/ByteUpDown.cs
@@ -321,62 +321,18 @@ protected override bool VerifyText(string text, ref Byte tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override byte FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
-
- byte number = 0;
- // Does this text represent a valid number ?
- if (byte.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
-
- ///
- /// Determines whether the step size in the parameter
- /// is larger 0 (valid) or not.
- ///
- /// returns true for valid values, otherwise false.
- ///
- private static bool IsValidStepSizeReading(object value)
+ protected override bool ParseText(string text, out byte number)
+ {
+ return byte.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
+
+ ///
+ /// Determines whether the step size in the parameter
+ /// is larger 0 (valid) or not.
+ ///
+ /// returns true for valid values, otherwise false.
+ ///
+ private static bool IsValidStepSizeReading(object value)
{
byte v = (byte)value;
return (v > 0);
diff --git a/source/NumericUpDownLib/DecimalUpDown.cs b/source/NumericUpDownLib/DecimalUpDown.cs
index 40e70d2..cb8e1bc 100644
--- a/source/NumericUpDownLib/DecimalUpDown.cs
+++ b/source/NumericUpDownLib/DecimalUpDown.cs
@@ -322,61 +322,18 @@ protected override bool VerifyText(string text, ref Decimal tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override decimal FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- decimal number = 0;
- // Does this text represent a valid number ?
- if (decimal.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
-
- ///
- /// Determines whether the step size in the parameter
- /// is larger 0 (valid) or not.
- ///
- /// returns true for valid values, otherwise false.
- ///
- private static bool IsValidStepSizeReading(object value)
+ protected override bool ParseText(string text, out decimal number)
+ {
+ return decimal.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
+
+ ///
+ /// Determines whether the step size in the parameter
+ /// is larger 0 (valid) or not.
+ ///
+ /// returns true for valid values, otherwise false.
+ ///
+ private static bool IsValidStepSizeReading(object value)
{
decimal v = (decimal)value;
return (v > 0);
diff --git a/source/NumericUpDownLib/DoubleUpDown.cs b/source/NumericUpDownLib/DoubleUpDown.cs
index b255226..8c0f08d 100644
--- a/source/NumericUpDownLib/DoubleUpDown.cs
+++ b/source/NumericUpDownLib/DoubleUpDown.cs
@@ -325,53 +325,10 @@ protected override bool VerifyText(string text, ref double tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override double FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- double number = 0;
- // Does this text represent a valid number ?
- if (double.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out double number)
+ {
+ return double.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter
diff --git a/source/NumericUpDownLib/FloatUpDown.cs b/source/NumericUpDownLib/FloatUpDown.cs
index e346800..78402d5 100644
--- a/source/NumericUpDownLib/FloatUpDown.cs
+++ b/source/NumericUpDownLib/FloatUpDown.cs
@@ -324,53 +324,10 @@ protected override bool VerifyText(string text, ref float tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override float FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- float number = 0;
- // Does this text represent a valid number ?
- if (float.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out float number)
+ {
+ return float.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter
diff --git a/source/NumericUpDownLib/LongUpDown.cs b/source/NumericUpDownLib/LongUpDown.cs
index 43f15a8..5a51c6a 100644
--- a/source/NumericUpDownLib/LongUpDown.cs
+++ b/source/NumericUpDownLib/LongUpDown.cs
@@ -321,53 +321,10 @@ protected override bool VerifyText(string text, ref long tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override long FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- long number = 0;
- // Does this text represent a valid number ?
- if (long.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out long number)
+ {
+ return long.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter
diff --git a/source/NumericUpDownLib/NumericUpDown.cs b/source/NumericUpDownLib/NumericUpDown.cs
index bae7716..9bf29d9 100644
--- a/source/NumericUpDownLib/NumericUpDown.cs
+++ b/source/NumericUpDownLib/NumericUpDown.cs
@@ -4,6 +4,7 @@ namespace NumericUpDownLib
using System;
using System.Globalization;
using System.Windows;
+ using static System.Net.Mime.MediaTypeNames;
///
/// Implements an Integer based Numeric Up/Down control.
@@ -321,61 +322,18 @@ protected override bool VerifyText(string text, ref int tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override int FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- int number = 0;
- // Does this text represent a valid number ?
- if (int.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
-
- ///
- /// Determines whether the step size in the parameter
- /// is larger 0 (valid) or not.
- ///
- /// returns true for valid values, otherwise false.
- ///
- private static bool IsValidStepSizeReading(object value)
+ protected override bool ParseText(string text, out int number)
+ {
+ return int.TryParse(text, NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
+
+ ///
+ /// Determines whether the step size in the parameter
+ /// is larger 0 (valid) or not.
+ ///
+ /// returns true for valid values, otherwise false.
+ ///
+ private static bool IsValidStepSizeReading(object value)
{
var v = (int)value;
return (v > 0);
diff --git a/source/NumericUpDownLib/SByteUpDown.cs b/source/NumericUpDownLib/SByteUpDown.cs
index ce7c64c..b05177c 100644
--- a/source/NumericUpDownLib/SByteUpDown.cs
+++ b/source/NumericUpDownLib/SByteUpDown.cs
@@ -321,54 +321,10 @@ protected override bool VerifyText(string text, ref sbyte tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override SByte FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
-
- sbyte number = 0;
- // Does this text represent a valid number ?
- if (sbyte.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out SByte number)
+ {
+ return SByte.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter
diff --git a/source/NumericUpDownLib/ShortUpDown.cs b/source/NumericUpDownLib/ShortUpDown.cs
index 4f71700..a48bd55 100644
--- a/source/NumericUpDownLib/ShortUpDown.cs
+++ b/source/NumericUpDownLib/ShortUpDown.cs
@@ -321,53 +321,10 @@ protected override bool VerifyText(string text, ref short tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override short FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- short number = 0;
- // Does this text represent a valid number ?
- if (short.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out short number)
+ {
+ return short.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter
diff --git a/source/NumericUpDownLib/UIntegerUpDown.cs b/source/NumericUpDownLib/UIntegerUpDown.cs
index 1565956..a199df1 100644
--- a/source/NumericUpDownLib/UIntegerUpDown.cs
+++ b/source/NumericUpDownLib/UIntegerUpDown.cs
@@ -321,53 +321,10 @@ protected override bool VerifyText(string text, ref uint tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override uint FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- uint number = 0;
- // Does this text represent a valid number ?
- if (uint.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out uint number)
+ {
+ return uint.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter
diff --git a/source/NumericUpDownLib/ULongUpDown.cs b/source/NumericUpDownLib/ULongUpDown.cs
index 4999cfc..d4e1724 100644
--- a/source/NumericUpDownLib/ULongUpDown.cs
+++ b/source/NumericUpDownLib/ULongUpDown.cs
@@ -321,53 +321,10 @@ protected override bool VerifyText(string text, ref ulong tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override ulong FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- ulong number = 0;
- // Does this text represent a valid number ?
- if (ulong.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out ulong number)
+ {
+ return ulong.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter
diff --git a/source/NumericUpDownLib/UShortUpDown.cs b/source/NumericUpDownLib/UShortUpDown.cs
index 2c82e23..5137613 100644
--- a/source/NumericUpDownLib/UShortUpDown.cs
+++ b/source/NumericUpDownLib/UShortUpDown.cs
@@ -321,54 +321,10 @@ protected override bool VerifyText(string text, ref ushort tempValue)
return false;
}
- ///
- /// Checks if the current string entered in the textbox is valid
- /// and conforms to a known format
- /// ( base method for more details).
- ///
- ///
- ///
- protected override ushort FormatText(string text, bool formatNumber = true)
- {
- if (_PART_TextBox == null)
- return Value;
- ushort number = 0;
- // Does this text represent a valid number ?
- if (ushort.TryParse(text, base.NumberStyle,
- CultureInfo.CurrentCulture, out number) == true)
- {
- // yes -> but is the number within bounds?
- if (number > MaxValue)
- {
- // Larger than allowed maximum
- _PART_TextBox.Text = FormatNumber(MaxValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- if (number < MinValue)
- {
- // Smaller than allowed minimum
- _PART_TextBox.Text = FormatNumber(MinValue);
- _PART_TextBox.SelectionStart = 0;
- }
- else
- {
- // Number is valid and within bounds, just format if requested
- if (formatNumber == true)
- _PART_TextBox.Text = FormatNumber(number);
- }
- }
- }
- else
- {
- // Reset to last value since string does not appear to represent a number
- _PART_TextBox.SelectionStart = 0;
- _PART_TextBox.Text = FormatNumber(Value);
- number = Value;
- }
- return LastEditingNumericValue;
- }
+ protected override bool ParseText(string text, out ushort number)
+ {
+ return ushort.TryParse(text, base.NumberStyle, CultureInfo.CurrentCulture, out number);
+ }
///
/// Determines whether the step size in the parameter