winforms: handling enter key for single line edit?

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?
 
P

PEACEMAKER

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);
}
 
M

Morten Wennevik

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]
 

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