TextBox ENTER and ESC sound OnKeyPress

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 11
Reputation: DanyLdon is an unknown quantity at this point 
Solved Threads: 1
DanyLdon's Avatar
DanyLdon DanyLdon is offline Offline
Newbie Poster

TextBox ENTER and ESC sound OnKeyPress

 
0
  #1
Jun 22nd, 2009
Hi i will describe my problem.
When focus is on TextBox and we press ENTER or ESC then we will hear that sound. I'm trying to disable that. Did any one got that problem before ? I was trying to create my own SilentTextBox which will inherit from TextBox and disable that sound by overriding OnKeyPress. OnKeyDown, OnKeyUp and OnPreviewKeyDown.

For example
  1. protected override void OnKeyPress(KeyPressEventArgs e)
  2. {
  3. if ((e.KeyChar != 13) || (e.KeyChar != 27))
  4. {
  5. base.OnKeyPress(e);
  6. }
  7. }

Unfortunately that doesn't disable that ping sound.
thx in advance for any help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,908
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 273
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: TextBox ENTER and ESC sound OnKeyPress

 
0
  #2
Jun 22nd, 2009
You must not use base.OnKeyPress(e); in your override. By doing so, you will first execute what is already programmed in the base class, which is a behaviour you don't want.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: TextBox ENTER and ESC sound OnKeyPress

 
0
  #3
Jun 22nd, 2009
You can't disable it. "you can't" == you can but after huge efforts. what does this sound means to you?! it means you haven't accept button on your forum, once you've this button you won't get this sound + TextBox class not getting this sound itself, but OS does.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 11
Reputation: DanyLdon is an unknown quantity at this point 
Solved Threads: 1
DanyLdon's Avatar
DanyLdon DanyLdon is offline Offline
Newbie Poster

Re: TextBox ENTER and ESC sound OnKeyPress

 
0
  #4
Jun 23rd, 2009
Thank you for reply. I decided to use combination of label and button works actually better now.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 1
Reputation: tanioskahi is an unknown quantity at this point 
Solved Threads: 0
tanioskahi tanioskahi is offline Offline
Newbie Poster

Re: TextBox ENTER and ESC sound OnKeyPress

 
0
  #5
Aug 20th, 2009
Your solution is correct, except that you should use
  1. (e.KeyChar != 13) && (e.KeyChar != 27)
because by using OR, when it's ENTER, it's not ESC, and the default handler is called (and vice-versa).
Last edited by tanioskahi; Aug 20th, 2009 at 9:49 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: pato212 is an unknown quantity at this point 
Solved Threads: 0
pato212 pato212 is offline Offline
Newbie Poster
 
0
  #6
32 Days Ago
Last edited by pato212; 32 Days Ago at 1:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 879
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 137
DdoubleD DdoubleD is offline Offline
Practically a Posting Shark
 
0
  #7
32 Days Ago
  1. // Stop the annoying BEEP when user presses ENTER or ESCAPE...
  2. protected override void OnKeyPress(KeyPressEventArgs e)
  3. {
  4. if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape)
  5. {
  6. e.Handled = true; // stop annoying beep
  7. }
  8.  
  9. // call base handler...
  10. base.OnKeyPress(e);
  11. }
Last edited by DdoubleD; 32 Days Ago at 3:10 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC