私がこれを持っているとしましょう:
private void txtAnalogValue_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//Non-numeric key pressed => prevent this from being input into the Textbox
e.SuppressKeyPress = true;
}
}
この:
private void txtAnalogValue_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
try
{
UpdateState(double.Parse(((TextBox)sender).Text));
}
catch (Exception ex)
{
((TextBox)sender).Text = ioElement.StateVal.ToString("0.00");
}
}
}
このコードがあまり意味をなさないことはわかっています。これは単なるテストです。問題は、KeyDown イベントの e.SuppressKeyPress = true が KeyUp イベントに影響を与えるので、Enter キーが受け入れられないということです。