Click here to Skip to main content
15,887,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have listed a portion of my KeyDown event code below. The KeyDown event can be executed by the user pressing Ctrl+Y. However, when this is done, there is a beep sound that I want to disable. I have also set the KeyPreview property of the form to True.

I thought the e.SuppressKeyPress = True statement would disable the beep, but it does not.

What statement do I need in order to stop the beep sound when the user presses the Ctrl+Y keys?

Private Sub frmAddEditAssets_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
           Case (Keys.Control + Keys.Y)
               e.SuppressKeyPress = True
               Call YearEndUpdate()
       End Select
Posted
Comments
[no name] 26-Oct-15 20:51pm    
Discussion here: http://www.codeproject.com/Questions/718539/System-beep-on-keyDown

Replace the e.SuppressKeyPress = true; with e.Handled = true;
 
Share this answer
 
Hi Dave,

Thank you for your prompt response. However, for some reason, even after changing the statement to e.Handled = true (from e.SuppressKeyPress = True), there is still a beep sound when the KeyDown event is executed.

Update: I realized later that the reason for the beep was because of the MessageBox.Show command. The beep was associated with the MessageBox, not the KeyDown event. I found that if I set the MessageBox icon as follows: MessageBoxIcon.Question, then there is no beep. All of the other MessageBox icons have a beep sound associated with them.
 
Share this answer
 
v2
Comments
[no name] 26-Oct-15 20:52pm    
You have added an answer and not a comment to the solution.
Member 11561472 26-Oct-15 20:54pm    
I did not see a Reply button.
Dave Kreskowiak 26-Oct-15 23:20pm    
Yes, you do. It says "Have a Question or Comment?". Click that.

Because you posted this as a Solution, I never got a notification that you posted this. I had to come back and stumble on it.
Dave Kreskowiak 26-Oct-15 23:22pm    
Well, the MessageBox isn't in your code snippet nor did you describe such behavior. Yeah, the beep is coming from the MessageBox because it's a blocking call. Your code is no longer running until the MessageBox is dismissed.

If you're trying to show a message, you could possible just create your own form and make it look like a message box. You can then create an instance of that form and show your message however you want, without the blocking call.
Member 11561472 27-Oct-15 12:13pm    
Dave, I am sorry that my code snippet didn't show the MessageBox. It was part of the YearEndUpdate subroutine that was called in my code. I was trying to keep things simple, and it didn't occur to me that the MessageBox was the problem at the time.

Thanks for the suggestion about creating my own form that can be made to look like a MessageBox. That is just what I need to do. Thanks for that. As you can tell, I am new at this. Thank you so much for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900