TabIndex changed to Enter for all forms in C#
How can i change TabIndex fr开发者_StackOverflowom "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?
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
}
}
You can bind all your textbox to the event "validation" (or something like that) and then call the same method which do the jump :)
精彩评论