Keydown事件无法正常工作 [英] Keydown event not working correctly
本文介绍了Keydown事件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码进行按键操作。但是这段代码不能正常工作。如果我按下回车键,控制器会转到另一个按钮。
I'm Using the following code for key down. But this code not working correctly. If I press a Enter key the control go to another button.
private void txtItemName_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
if (txtItemName.Text == string.Empty)
{
txtItemName.BorderBrush = Brushes.Red;
}
else
{
txtItemName.BorderBrush = Brushes.White;
ComboCategory.Focus();
}
}
else
{
txtItemName.BorderBrush = Brushes.LightBlue;
}
}
推荐答案
您还应该覆盖方法isInputKey。 />
在这里您可以定义例如Enter-Key属于您的控件而不应该切换到另一个控件。
You should also override the method "isInputKey".
Here you could define that for example the Enter-Key belongs to your control and not should switch to another control.
protected override bool IsInputKey(System.Windows.Forms.Keys keyData)
{
if (keyData == Keys.Enter) {
return true;
} else if (keyData == Keys.Back) {
return true;
} else if (keyData == Keys.Tab) {
return true;
} else {
return base.IsInputKey(keyData);
}
}
(你应该修改你需要的代码片段......)
(you should modify the code-snippet like you need ...)
检查连接到控件属性的事件
Check the event connected to control properties
这篇关于Keydown事件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文