Enter Key in a TextBox

J

Jose Egea

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
 
C

ClayB [Syncfusion]

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
 
J

Jose Egea

Hi Peter:
I guess it has, because I'm typing into the textbox.
Is there another possibility?
 
J

Jose Egea

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top