The solution did not work for me, as I was getting unpredictable behavior when editing numericupdown. For example, I could not change one number and save the result, because the text contained the final character ("%" in the question "in my case").
So, I am updating the class with some code to parse the decimal and store the value. Pay attention to using ChangingText
, otherwise it would trigger a modification event in loops
class EuroUpDown : NumericUpDown { protected override void UpdateEditText() { ChangingText = true; Regex decimalRegex = new Regex(@"(\d+([.,]\d{1,2})?)"); Match m = decimalRegex.Match(this.Text); if (m.Success) { Text = m.Value; } ChangingText = false; base.UpdateEditText(); ChangingText = true; Text = this.Value.ToString("C", CultureInfo.CurrentCulture); } }
source share