Prevent Beep on Enter (Again)

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.
 
A

Armin Zingler

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
 

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