每当我将焦点从一个文本框更改到另一个文本框时,它就会发出恼人的警告/错误蜂鸣声。
例子:
public void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
textBox2.Focus();
}
每当我按下 Enter 时,它会将焦点更改为 textBox2 并发出警告蜂鸣声。
如能提供任何帮助来禁用此功能,我们将不胜感激。 谢谢。
最佳答案
我认为您想将 e.Handled = true
添加到事件处理程序:
public void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
textBox2.Focus();
e.Handled = true;
}
}
一个侧节点:你应该能够使用 KeyCode
而不是 KeyChar
属性,避免转换:
public void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
textBox2.Focus();
e.Handled = true;
}
}
关于c# - 更改焦点时禁用警告/错误蜂鸣,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1806049/