|
-
Jun 16th, 2008, 10:20 AM
#1
Thread Starter
New Member
[RESOLVED] [2008] Stop Beep sound when pressing Enter on TextBox
Hello to the community,
My working environment:
OS : Vista
VS :2008
If I press Enter key when a TextBox has focus, a BEEP sound plays.
I want to prevent this sound.
( I want to handle this key by KeyDown event to go next control using Control.Select)
Please help me
-
Jun 16th, 2008, 01:44 PM
#2
Fanatic Member
Re: [2008] Stop Beep sound when pressing Enter on TextBox
You can try Console.Beep which beeps through the computer speaker if there is one.
http://msdn.microsoft.com/en-us/library/8hftfeyw.aspx
-
Jun 16th, 2008, 02:28 PM
#3
Re: [2008] Stop Beep sound when pressing Enter on TextBox
your best bet is to set the forms keypreview property to True and handle the event at the form level in the KeyPress event. To stop the beep you add the line e.Handled = True
an Example:
Code:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar = ControlChars.Cr Then
e.Handled = True
Me.SelectNextControl(Me.ActiveControl, True, True, False, True)
End If
End Sub
-
Jun 16th, 2008, 02:33 PM
#4
Re: [2008] Stop Beep sound when pressing Enter on TextBox
You handle the KeyPress event of the textbox, and test if e.KeyChar = Chr(13) then set e.Handled = True and select the next control in tab order.
Something like this:
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
e.Handled = True 'This prevents the beep to sound
Me.SelectNextControl(CType(sender, Control), True, True, True, True)
End If
End Sub
Edit: Bmahler beats me again
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jun 16th, 2008, 02:35 PM
#5
Fanatic Member
Re: [2008] Stop Beep sound when pressing Enter on TextBox
Oh wow, yet again I failed. Completly misread the question.
sorry!
-
Jun 16th, 2008, 05:16 PM
#6
Thread Starter
New Member
Re: [2008] Stop Beep sound when pressing Enter on TextBox
Thanks to all of you.
I am using KeyDown event to handle Enter key and move to next control
and here is what I am able to to resolve it like:
vb Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
Me.TextBox2.Select()
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|