But I'm using the Form_KeyDown(object sender, KeyEventArgs e)
and the string representation of the decimal key "." is a "n".
s += (char)e.KeyValue; // s = "n" and I click the decimal key
Why it's so different?
How can I get the decimal character from the Regional Settings?
KeyEventArgs contains the key number of the keyboard , while
KeyPressEventArgs contains the key pressed (see
http://msdn2.microsoft.com/en-us/lib...eventargs.aspx
for detailed information). So you better use Form_KeyPress instead of
Form_KeyDown;
The decimal character (and more info) can be obtained from class
NumberFormatInfo (using System.Globalization). In the next example all keys
will be send to the control that has focus (like a textbox), but not if the
decimal seperator is pressed:
private void Form_KeyPress(object sender, KeyPressEventArg e)
{
if (NumberFormatInfo.CurrentInfo.NumberDecimalSeperat or ==
e.KeyChar.ToString())
{
// Decimal seperator pressed
e.Handled = true; // don't send the character to the focused control
}
}
Regards,
Anne