如何检测C#中的Tab键按下?
问题描述:
我想检测何时在文本框中按下Tab键,然后将面板中的下一个文本框聚焦.
I want to detect when tab key is pressed in a textBox and focus the next textbox in the panel.
我已经尝试过keyPressed方法和keyDown方法.但是,当我运行程序并调试时,按Tab键不会调用这些方法. 这是我的代码.
I have tried out keyPressed method and keyDown method. But when I run the program and debug those methods are not calling when the tab key is pressed. Here is my code.
private void textBoxName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
textBoxUsername.Focus();
}
}
private void textBoxName_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar==(char)Keys.Tab)
{
textBoxUsername.Focus();
}
}
请纠正我.谢谢.
答
转到文本框的属性,并指定tabindex的正确顺序
go to the properties of text box and assign correct order of tabindex