【发布时间】:2012-05-17 18:46:47
【问题描述】:
我有一个简单的表单用于输入:
12 个按钮,1 个文本框(禁用和只读)
这就是我处理输入的方法
Login_KeyDown() 是我为每个 UI 组件和表单本身的所有 KeyDown 调用的常用方法..
private void Login_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Application.Exit();
}
else if (e.KeyCode == Keys.NumPad9 || e.KeyCode == Keys.D9)
{
button3.BackgroundImage = Properties.Resources.button_hover;
button3.ForeColor = Color.White;
pin.Text = pin.Text + "9";
}
else if (e.KeyCode == Keys.Back)
{
button11.BackgroundImage = Properties.Resources.button_hover;
button11.ForeColor = Color.White;
if (pin.Text.Length > 0)
pin.Text = pin.Text.Substring(0, pin.Text.Length - 1);
}
else if (e.KeyCode == Keys.Enter)
{
MessageBox.Show(pin.Text);
}
}
此代码在我启动应用程序时工作正常,但在我点击任何组件后,其余代码工作正常,但“输入关键条件”不起作用。
我的猜测是“输入关键条件”不适用于 UI 组件或类似的东西。
我也尝试过使用 "Key Press Event",它使用 KeyPressEventArgs 然后检查 KeyChar == 13 但这也不起作用。
有什么问题,我该如何解决?
附言 我没有为任何按钮设置任何按钮点击事件,该应用程序是 100% 基于 KBoard。
【问题讨论】: