winforms: handling enter key for single line edit?

  • Thread starter Thread starter PEACEMAKER
  • Start date Start date
P

PEACEMAKER

I want to take an action when the user hits the enter key on a single line
edit on the form but I can't find any events that handle the enter key. The
char and keyup events still cause a beep on the carriage return although it
sends the linefeed char. I'm sure there is a better way to accomplish this?
 
nevermind, I got it

protected override bool ProcessDialogKey(Keys keyData)
{
if(keyData == Keys.Enter && QuizAnswerTextBox.Focused==true)
{
QuizAnswerTextBox.Text = "";
return true;
}
return base.ProcessDialogKey (keyData);
}
 
Hi PEACEMAKER,

You could also catch it if you handle the keydown event for the form while
setting KeyPreview to true.

Happy coding!
Morten Wennevik [C# MVP]
 
Back
Top