Does anybody know why the system emits a beep when the Enter key is pressed
inside a TextBox? I know how to stop the beep from happening but I was
wondering what the purpose of the beep is in the first place.
TIA
--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
> Hi all,
>
> Does anybody know why the system emits a beep when the Enter key is pressed
> inside a TextBox? I know how to stop the beep from happening but I was
> wondering what the purpose of the beep is in the first place.
>
> TIA
This happens in a single-line (as opposed to multi-line) text box. I
believe the reason behind this is to indicate to the user that pressing
[enter] in a single-line text box won't create a new line.
Disable the sound in the system's sound settings.
<http://www.google.de/groups?q=herfried+beep+textbox+dotnet>
--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
That is not nice thing to do... user might mind...
Put this code on TextBox_KeyPress
If Microsoft.VisualBasic.Asc(eventargs.KeyChar) =13 then
eventargs.Handled = True
End If
--
Pozdrav,
Josip Medved
http://www.jmedved.com
public class TextBoxEx : System.Windows.Forms.TextBox
{
const int WM_GETDLGCODE = 0x0087;
const int DLGC_WANTARROWS = 0x0001;
const int DLGC_WANTTAB = 0x0002;
const int DLGC_WANTALLKEYS = 0x0004;
const int DLGC_WANTMESSAGE = 0x0004;
const int DLGC_HASSETSEL = 0x0008;
const int DLGC_DEFPUSHBUTTON = 0x0010;
const int DLGC_UNDEFPUSHBUTTON = 0x0020;
const int DLGC_RADIOBUTTON = 0x0040;
const int DLGC_WANTCHARS = 0x0080;
const int DLGC_STATIC = 0x0100;
const int DLGC_BUTTON = 0x2000;
public TextBoxEx()
{
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress (e);
switch ((Keys)e.KeyChar)
{
case Keys.Enter:
e.Handled = true;
break;
case Keys.Escape:
e.Handled = true;
break;
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if( m.Msg == (int)WM_GETDLGCODE )
{
m.Result = new IntPtr( (int)DLGC_WANTCHARS |
(int)DLGC_WANTARROWS |
(int)DLGC_HASSETSEL |
(int)DLGC_WANTALLKEYS |
m.Result.ToInt32() );
}
}
}
"Rob Windsor [MVP]" <rwin...@NO.MORE.SPAM.bigfoot.com> wrote in message
news:%23SBuHnq...@TK2MSFTNGP11.phx.gbl...
That may work, but it's doing it the hard way. ProcessDialogKey lets
you do the same without messing with WndProc, and it will work for Escape
too. In VB, try something like:
Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
Select Case keyData
Case Keys.Enter, Keys.Return, Keys.Escape: Return True
Case Else: Return MyBase.ProcessDialogKey(keyData)
End Select
End Function
Jeremy
Private Sub TextBox1_KeyPress(blah blah)
If KeyAscii = 13 Then
e.Handled = True ' prevents beep when enter is pressed in a textbox
Button1.PerformClick() ' performs button click event
End If
End Sub
From http://www.developmentnow.com/g/29_2004_3_0_0_119644/TextBox-Beep-on-Enter-Key.htm
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/