The OnKeyDown event is generated by the Windows WM_KEYDOWN event. WM_KEYDOWN is sending our application a Key.Decimal event.
Similarly, the OnKeyPress event is generated directly from the WM_CHAR event. In the case of French - Canadian regional settings (with Canadian French keyboard), Windows sends a WM_CHAR event with a period when the user presses the number pad decimal key. However, in the case of French - Belgian settings with the "Belgian (Comma)" input settings, Windows sends a WM_CHAR event with a comma.
So this is neither a .NET bug nor a bug in our application. The regional input settings affects the behavior of the Decimal key.
However, some applications do respond differently in French - Canadian settings. For example, both Excel and Windows Calculator both translate Keys.Decimal into a comma instead of a period. These applications may have special handling for this case.
We could add code to our application to track a decimal key and handle it differently. For example:
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyData == Keys.Decimal)
m_DecimalKey = true;
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
...
if (m_DecimalKey || e.KeyChar == CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator)
{
// this is a decimal separator
}
}
protected virtual void OnKeyUp(KeyEventArgs e)
{
if (e.KeyData == Keys.Decimal)
m_DecimalKey = false;
}