How to focus on button.
-
Hi all, I have a textbox and one button in my form. After entering text in textbox I have to click on Ok button. Insted of click on Ok button I want to press enter.
-
Hi all, I have a textbox and one button in my form. After entering text in textbox I have to click on Ok button. Insted of click on Ok button I want to press enter.
-
Hi all, I have a textbox and one button in my form. After entering text in textbox I have to click on Ok button. Insted of click on Ok button I want to press enter.
Register for the KeyDown-Event of your textbox. Within the handler check if the KeyCode equals Enter and call your OK-method.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
What about using a KeyPreviewDown event handler for the text box, then you can use the same code you use in your button Click event handler
Life goes very fast. Tomorrow, today is already yesterday.
Hi, You can do it like this.
textBox.PreviewKeyDown += new KeyEventHandler(textBox_PreviewKeyDown);
private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
// Enter without modifiers.
if (e.Key == Key.Return && Keyboard.Modifiers == ModifierKeys.None)
{
DoSameThingAsOKButton();e.Handled = true; return;
}
}Hope this helps, Bart
-
Hi, You can do it like this.
textBox.PreviewKeyDown += new KeyEventHandler(textBox_PreviewKeyDown);
private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
// Enter without modifiers.
if (e.Key == Key.Return && Keyboard.Modifiers == ModifierKeys.None)
{
DoSameThingAsOKButton();e.Handled = true; return;
}
}Hope this helps, Bart
-
Hi all, I have a textbox and one button in my form. After entering text in textbox I have to click on Ok button. Insted of click on Ok button I want to press enter.
You don't need any code for this, just: - make sure TextBox.AcceptsReturn is false - have an OK button with DialogResult not equal to None - set your form's AcceptButton to that OK button. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in