Unable to remove Beep on Alt+A

P

Paul

I created a sample Project with a basic form and one text box. I put
"e.Handled = True" on every KeyDown, KeyPress and KeyUp event for both
the Form and the TextBox. When I run the app, and press the Alt+A (or
any Alt+character) button, it beeps (very annoying). Does anyone know
why and how to fix it?
 
A

aclauson

I had the same problem, except I needed the beep removed on the entire
form. One possible way is to put a Menu Strip on the form and set
visible to false if you don't use it.

The solution I found was to set e.SuppressKeyPress to True after
handling the form's KeyDown event. So your code would look something
like:

Private Sub frm_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt AndAlso e.KeyValue = Keys.A Then
<EXECUTE ALT-A CODE HERE>
e.SuppressKeyPress = True
End If
End Sub

The form will still beep when you hit another Alt combination that is
not explicitly handled and then the args keypress suppressed as above.

Drew
 

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