更新时间:2023-02-11 08:39:17
我同意改变标准行为可能会混淆用户的评论。但是要消耗击键,你应该在KeyDown事件处理程序中设置SuppressKeyPress属性,例如
I agree with the comment that altering a standard behaviour may confuse users. However to consume a keystroke you should set the SuppressKeyPress property in the KeyDown event handler, e.g.
private void TextBox_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == System.Windows.Forms.Keys.Back) {
e.SuppressKeyPress = true;
// no need to set e.Handled
otherTextBox.Select();
}
}
这是怎么做的,但我认为你***不要为TextBoxes设置顺序Tab键顺序使用Tab键和Shift-Tab键在它们之间导航。
Alan
Thats how it''s done, but I do think you would be better off setting a sequential tab order for the TextBoxes and navigating between them using the Tab and Shift-Tab keys.
Alan
如果有三个文本框放在这样的一个标签到另一个的方式,即标签索引是一个接一个,你可以使用 SendKeys.Send
[ ^ ]将shift + tab的组合发送到标签到上一个文本框。
If three textboxes are layed out in such a way that one tabs to the other i.e. the tab indexes are one after the other, you can use SendKeys.Send
[^] to send a combination of "shift + tab" to tab to previous text box.