The call
CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator
gets the decimal separator for the current user interface culture. You can use other cultures to get the separator for other languages.
EDIT
From the 166 cultures that are reported in my system (CultureInfo.GetCultures(CultureTypes.SpecificCultures).Count()
), it seems that only two separators are used: period and comma. You can try this in your system:
var seps = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(ci => ci.NumberFormat.NumberDecimalSeparator)
.Distinct()
.ToList();
Assuming that this is true, this method may be helpful (note that the keyCode
is OR'ed with the modifiers
flag in order to eliminate invalid combinations):
private bool IsDecimalSeparator(Keys keyCode, Keys modifiers)
{
Keys fullKeyCode = keyCode | modifiers;
if (fullKeyCode.Equals(Keys.Decimal)) // value=110
return true;
string uiSep = CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
if (uiSep.Equals("."))
return fullKeyCode.Equals(Keys.OemPeriod); // value=190
else if (uiSep.Equals(","))
return fullKeyCode.Equals(Keys.Oemcomma); // value=188
throw new ApplicationException(string.Format("Unknown separator found {0}", uiSep));
}
A last note: According to Keys enumeration, the value 46 that you mention corresponds to the DEL (Delete) key (i.e. the point when Num Lock is OFF).