问题
How can i change TabIndex from "tab" to "enter" for all forms in my win application. I know i can use event for every textbox like:
If (Keys.Enter Then) {
SendKeys.Send("{TAB}")
}
but i don't want to do this 1000 times. Can i make this by default for all textboxes and forms?
回答1:
You can try to enable forms KeyPreview property. Then you'll be able to handle keystroke before controls get it
private void Form_KeyDown(object sender, KeyEventArgs e)
{
if(Keys.Enter == e.KeyCode)
{
SendKeys.Send("{TAB}");
e.Handled = true;//set to false if you need that textbox gets enter key
}
}
回答2:
You can bind all your textbox to the event "validation" (or something like that) and then call the same method which do the jump :)
来源:https://stackoverflow.com/questions/7254835/tabindex-changed-to-enter-for-all-forms-in-c-sharp