Prevent Beep on Enter (Again)

  • Thread starter Thread starter Jay Banks
  • Start date Start date
J

Jay Banks

I know this was recently posted in reference to a textbox, but I'm
having a similar problem, and can't keep it from beeping. I'm using a
NumericUpDown control instead of a textbox. I've tried this code in the
KeyPress and the KeyDown events. None of the below code prevents the beep.

If e.KeyCode = Keys.Enter Then
e.Handled = True
...
End If

If e.KeyChar = vbCr Then
e.Handled = True
...
End If

If e.KeyChar = Chr(13) Then ' Same as above
e.Handled = True
...
End If

J.
 
Jay Banks said:
I know this was recently posted in reference to a textbox, but I'm
having a similar problem, and can't keep it from beeping. I'm using
a
NumericUpDown control instead of a textbox. I've tried this code in
the KeyPress and the KeyDown events. None of the below code
prevents the beep.

Derive your own Control from NumericUpdown and add this code:

Protected Overrides Sub OnTextBoxKeyPress( _
ByVal source As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs)

If e.KeyChar = Chr(13) Then
e.Handled = True
Else
MyBase.OnKeyPress(e)
End If
End Sub



--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top