469,934 Members | 2,278 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Enter Key in a TextBox

Hello:
I'm trying to execute a function when the user press Enter key in a TextBox.
But something is happening in my form because after pressing a button, when
I press the Enter key in the TextBox, the application executes the click
event of the last button selected instead of the keypress event of the
TextBox. Any key event happen in my form, even the keypreview event is
ignored. The propertie AcceptsReturn is set to false and AcceptButton to
none.
I can't understand the reason.

Thanks in advance for your help

Best regards
Nov 16 '05 #1
3 19489
Clicking a button gives it input focus. Try adding this.textBox1.Focus() at
the bottom of your button handler to set the input focus back to your
textBox1.

===================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Jose Egea" <je***@innovem.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello:
I'm trying to execute a function when the user press Enter key in a TextBox. But something is happening in my form because after pressing a button, when I press the Enter key in the TextBox, the application executes the click
event of the last button selected instead of the keypress event of the
TextBox. Any key event happen in my form, even the keypreview event is
ignored. The propertie AcceptsReturn is set to false and AcceptButton to
none.
I can't understand the reason.

Thanks in advance for your help

Best regards

Nov 16 '05 #2
Hi Peter:
I guess it has, because I'm typing into the textbox.
Is there another possibility?


"Peter Jausovec" <Peter Ja******@discussions.microsoft.com> escribió en el
mensaje news:47**********************************@microsof t.com...
Jose,

Are you sure that TextBox control has focus ?

"Jose Egea" wrote:
Hello:
I'm trying to execute a function when the user press Enter key in a TextBox. But something is happening in my form because after pressing a button, when I press the Enter key in the TextBox, the application executes the click
event of the last button selected instead of the keypress event of the
TextBox. Any key event happen in my form, even the keypreview event is
ignored. The propertie AcceptsReturn is set to false and AcceptButton to
none.
I can't understand the reason.

Thanks in advance for your help

Best regards

Nov 16 '05 #3
Thanks for your answer, but after investigating a little more I have
discovered that the issue is around mdi forms that I'm using in this
application.
I have a MDI child form that open another MDI child form this way when I
press a button:
private void button1_Click(object sender, System.EventArgs e)
{
fChild2=new frmChild2();
fChild2.MdiParent=this.MdiParent ;
fChild2.Show();
}

When I close this second child form and the first child form recover the
focus, if I got into a textbox of that first child form and press Enter key
the click button event fires instead of the key press event.
I have checked that the focus in in the textbox when I press the Enter.
I have a small project to check the effect.

Is there any explanation?
Thanks for your help again.

Best regards

"ClayB [Syncfusion]" <cl***@syncfusion.com> escribió en el mensaje
news:uT**************@TK2MSFTNGP09.phx.gbl...
Clicking a button gives it input focus. Try adding this.textBox1.Focus() at the bottom of your button handler to set the input focus back to your
textBox1.

===================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Jose Egea" <je***@innovem.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello:
I'm trying to execute a function when the user press Enter key in a

TextBox.
But something is happening in my form because after pressing a button,

when
I press the Enter key in the TextBox, the application executes the click
event of the last button selected instead of the keypress event of the
TextBox. Any key event happen in my form, even the keypreview event is
ignored. The propertie AcceptsReturn is set to false and AcceptButton to
none.
I can't understand the reason.

Thanks in advance for your help

Best regards


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Steve | last post: by
reply views Thread by Tom Edelbrok | last post: by
7 posts views Thread by Marc | last post: by
6 posts views Thread by Mark B | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.