473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Trapping Enter key?

Is there a simple way to prevent the system from beeping when I hit the
Enter key in a single-line text box?

I'm trapping the KeyDown event to intercept the key press and advance the
focus to the next control. But I still get an annoying beep. Any way to
silence it? Thanks

--
Dave Veeneman
Chicago
Nov 16 '05 #1
5 6679
Here is an example to capture the enter key.

protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
{
if( keyData == Keys.Enter )
{
MessageBox.Show( "Enter pressed!" );
return true;
}
return base.ProcessCmdKey( ref msg, keyData );
}
Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html

"Dave Veeneman" <da****@nospam.com> wrote in message
news:e#**************@TK2MSFTNGP12.phx.gbl...
Is there a simple way to prevent the system from beeping when I hit the
Enter key in a single-line text box?

I'm trapping the KeyDown event to intercept the key press and advance the
focus to the next control. But I still get an annoying beep. Any way to
silence it? Thanks

--
Dave Veeneman
Chicago

Nov 16 '05 #2
Here's a similar solution:

http://www.syncfusion.com/FAQ/WinFor...c94c.asp#q915q

See # 27.15
Nov 16 '05 #3
Here's the code for the derived TextBox I created. It doesn't beep when the
Enter key is pressed. Instead, it advances the focus to the next control.
public class MyCustomTextBox : System.Windows.Forms.TextBox
{
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Return)
{
SendKeys.Send("{TAB}");
return true;
}
else
{
return base.ProcessDialogKey(keyData);
}
}
}
The code is based on
http://www.syncfusion.com/FAQ/WinFor...c94c.asp#q915q, items 27.11 and
27.15.
Nov 16 '05 #4
Here's a similar solution:

http://www.syncfusion.com/FAQ/WinFor...c94c.asp#q915q

See # 27.15
Nov 16 '05 #5
Here's the code for the derived TextBox I created. It doesn't beep when the
Enter key is pressed. Instead, it advances the focus to the next control.
public class MyCustomTextBox : System.Windows.Forms.TextBox
{
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Return)
{
SendKeys.Send("{TAB}");
return true;
}
else
{
return base.ProcessDialogKey(keyData);
}
}
}
The code is based on
http://www.syncfusion.com/FAQ/WinFor...c94c.asp#q915q, items 27.11 and
27.15.
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ganesh | last post by:
Hi Experts I have an aspx page in which I am providing a search facility apart from other matters. I have placed an image button. I have several dropdown lists and textboxes in the page to...
1
by: kurt klingbeil | last post by:
I hope someone can illuminate some error handling mysteries: I read that if a func/sub doesn't do it's own error handling, control propagates up the call stack to the sub that does have an active...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
3
by: Dave Veeneman | last post by:
Is there a simple way to prevent the system from beeping when I hit the Enter key in a single-line text box? I'm trapping the KeyDown event to intercept the key press and advance the focus to...
1
by: Randy | last post by:
Hello All, I'm trying to trap the enter key in my dataGrid using the event... aColumnTextColumn.TextBox.KeyPress += new KeyPressEventHandler(DateKeyPress); The event fires when there is a key...
10
by: Perry van Kuppeveld | last post by:
Hi, I have a problem with formatting a table including text fields wich can contain up to 255 chars. I need a table with 3 columns: - First column 50 % over the with a rowspan of the total...
4
by: Bernie Yaeger | last post by:
I'm building a custom textbox for numbers only (actually two of them - one for integers and one that allows currency entries, but let's discuss the integer only control). I'm having a problem...
4
by: promiscuoustx | last post by:
The problem is that my code below used to run wonderfully, until the instructor decided that he wants to use characters instead of integers, and wants my code to trap the bad and have the program...
2
by: ApexData | last post by:
Using a continuous form I would like to require 1-field in each record to have data before the record is saved. In the table I set a single date field as required = yes, and this works for me. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.