NumericUpDown: accept both a comma and a decimal separator

Is there a way to get C # NumericUpDown to accept both a comma and a period to separate decimal values?

I set up a text box for this (almost replacing the dots with commas), but I'm surprised there is no other way.

This one explains how to change the delimiter, but I would like to use both of these options.

+4
source share
3 answers

The NumericUpDown element uses an operating system culture to use commas or periods as delimited separators.

(.. ), , :

private void numericUpDown1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar.Equals('.') || e.KeyChar.Equals(','))
        {
            e.KeyChar = ((System.Globalization.CultureInfo)System.Globalization.CultureInfo.CurrentCulture).NumberFormat.NumberDecimalSeparator.ToCharArray()[0];
        }
    }

NumericDecimalSeparator

+8

Nicolas R, , NumericUpDown ( ClipBoard Ctrl + V).

: NumericUpDown Control, , Text. Intellisense. Text, ValueChanged :

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
    numericUpDown1.Text = numericUpDown1.Text.Replace(',', '.');
}

: https://msdn.microsoft.com/en-us/library/cs40s7ds.aspx

+1

For the standard NumericUpDown control, the decimal character is determined by the regional settings of the operating system.

0
source

Source: https://habr.com/ru/post/1545263/


All Articles