how to suppress beep (beep sound)

G

Guest

When I press the Enter key in a Textbox I get a beep sound. But when I press
the Enter key in a combobox, I don't get the beep sound. Is there a way to
suppress the beep? How to do this?

Thanks
 
A

Anders B

I've experienced the same thing when I did a quick "command style" textbox
that I wanted to fire off the command entered in the box when you press
enter.. and it all worked good with the exception that it fired off the Beep
sound. Since its basically telling you that you cant create a new line in a
single-line box.

So what I did was making the textbox multiline and use the keydown event to
figure out of I pressed enter and then cleared the textbox and sent the
command.. And since it was a multiline box it didnt complain about the new
line that pressing enter does.

Not sure if you can do the same somehow.. I know its a dirty trick but
worked for me :p I don't know if you're trying to handle something when you
press enter or just want to get rid of the beep.
 
G

Guest

When I press the Enter key in a Textbox I get a beep sound. But when I
press
the Enter key in a combobox, I don't get the beep sound. Is there a way to
suppress the beep? How to do this?

I believe there is a windows issue with beeps and the enter key. Try
running without the min/restore/close feature in the window (ie set the
form's ControlBox=false). This may (no promises) stop the beep when you hit
the enter key, but you will have a window without a control box in the upper
right corner. Put the control box back (ControlBox=true), and the beep will
return. In theory, there is a way to have ControlBox=true and have a
beep-less enter key. You intercept WM_MENUCHAR, and return MNC_CLOSE from
the window procedure. I have never tested this, so once again, no promises.
I think the beep is a windows response to a failed menu access key or
something like that.

What I do is live with the beeps because I want a ControlBox true and I want
to keep things simple.
 
S

Stephany Young

There are NO windows issue with beeps and the enter key.

If you press the Enter key in a TextBox that is NOT MultiLine then you will
get a beep. This is by design because you can't enter a newline in such a
TextBox.

To suppress, the beep, simply handle the KeyPress event of the TextBox and
if it was the Enter key that was pressed the set e.handled to true before
allowing the event handler to terminate. If you wish some other action to
occur when the Enter key is pressed then put code for that in the same
place.
 

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