Trapping Enter key?

  • Thread starter Thread starter Dave Veeneman
  • Start date Start date
D

Dave Veeneman

Is there a simple way to prevent the system from beeping when I hit the
Enter key in a single-line text box?

I'm trapping the KeyDown event to intercept the key press and advance the
focus to the next control. But I still get an annoying beep. Any way to
silence it? Thanks
 
Here's the code for the derived TextBox I created. It doesn't beep when the
Enter key is pressed. Instead, it advances the focus to the next control.


public class MyCustomTextBox : System.Windows.Forms.TextBox
{
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Return)
{
SendKeys.Send("{TAB}");
return true;
}
else
{
return base.ProcessDialogKey(keyData);
}
}
}


The code is based on
http://www.syncfusion.com/FAQ/WinForms/FAQ_c94c.asp#q915q, items 27.11 and
27.15.
 
Back
Top