Prevent "ding" noise when user presses enter in ComboBox

I

illegal.prime

Hi all, very trivial request. I have a windows form application that
is working fine. However, users find it a little annoying when they
press "enter" in the combobox, they hear a "ding" noise. Implying the
action is prohibited - when in fact that is expected behavior for the
user to use.

Currently the ComboBox has an event handler for KeyUp that has a
condition if the key is enter (e.KeyCode == Keys.Enter). In that
condition I set e.Handled to true.

Any suggestions?

Thanks,
Novice
 
J

Jared

Use KeyDown + test against Return NOT ENTER KEY, its just a pain to write
this up for 100 controls...

Private Sub txEmail_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txEmail.KeyDown
If e.KeyCode = Keys.Return Then e.SuppressKeyPress = True
End Sub
 
M

Markus

Hi all, very trivial request. I have a windows form application that
is working fine. However, users find it a little annoying when they
press "enter" in the combobox, they hear a "ding" noise. Implying the
action is prohibited - when in fact that is expected behavior for the
user to use.


Maybe it's not a technical solution (where I don't know any), but rather
a communication/project management solution:

- If people like the ding sound, they should have this ding sound also
in your application. They are use to it, and most of them like it, as
they have switched them on.

- Those, who don't like the ding sound (like me ;-)) have switched them
off anyways in the windows sound schema settings.

- And finally a technical proposal: If you don't want to popup something
with a ding-sound, just make another control that gets a red error
message. It would just be another kind of feedback to the user - not
the standard way, but maybe also a good way (I don't know, what
exactly you want to achieve).

Markus
 
I

illegal.prime

My version of .Net doesn't have a member (specifically a property) on
KeyEventArgs called SuppressKeyPress.

Besides which, based on the name of the property I don't think that is
actually what I want to do. I want the event to still work (so I can
handle it in the KeyUp event handler), I just don't want the control to
produce that ding noise when the user presses enter.

Novice
 
I

illegal.prime

Wow... so this question has actually been asked many times before - the
issue was the search criteria I was using in Google groups.

Here are some related postings:
http://groups.google.com/group/micr...entArgs+KeyChar+enter&rnum=8#fc70d2e12650c108

http://groups.google.com/group/micr...ntArgs+KeyChar+enter&rnum=20#f5433ef12e1dbbd1

http://groups.google.com/group/micr...ntArgs+KeyChar+enter&rnum=15#15d3d594666e6e75

Anyway, my solution was slightly different from everyone else's.
Basically, I wanted to suppress the ding/beep noise that is made
because the control (ComboBox) doesn't recognize the key press as a
valid key press. With most controls, you can simply write your own
class that extends the control (for example TextBox) and then override
the IsInputKey method such that you return true if the key pressed was
enter and in all other cases just return base.IsInputKey(keyData) -
i.e. let the base control what is valid for the rest of the keys.
However ComboBox appears to be broken. In that it's KeyPress method
doesn't pay attention to (i.e. use) this method IsInputKey - it appears
to have been hardcoded to complain if the user presses the enter key.

However, not only did I not want the control not to ding, but I also
wanted to process the event when the user presses enter. Therefore, I
still wanted to get the enter key being pressed event in my key up
event handlers (that use my new class), so my solution was to create my
own class that extends ComboBox and override the OnKeyPress method:
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
base.OnKeyUp(new KeyEventArgs(Keys.Enter));
e.Handled = true;
return;
}
base.OnKeyPress (e);
}

You don't even need the "return;" statement in there, since the
e.Handled tells the base class (ComboBox) not to process this.

Hope this is useful to someone,
Novice
 

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