Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handle KeyDown Event...Get rid of Beep?

Status
Not open for further replies.

bitwise

Programmer
Mar 15, 2001
269
US
I have a simple textbox that processes the KeyDown event so that when the user hits the 'Enter' key it performs the necessary function. My question is, it makes a beep sound when you hit 'Enter' and process the event. Can I get rid of this beep sound somehow?

Thanks,
-bitwise

FYI, HERE IS THE CODE:

Private Sub TextBoxDeposits_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBoxDeposits.KeyDown
If TextBoxDeposits.Text <> [String].Empty Then
If e.KeyCode = Keys.Enter Then
Dim decCurDeposit As Decimal
Dim strCurDeposit As String

decCurDeposit = CDec(TextBoxDeposits.Text)
strCurDeposit = decCurDeposit.ToString("c")

myDeposits = myDeposits + decCurDeposit

LabelTotal.Text = myDeposits.ToString("c")
ListBoxDeposits.Items.Add(strCurDeposit)

TextBoxDeposits.Text = ""
e.Handled = True
End If
End If
End Sub
 
Setting e.Handled = True in KeyDown has no effect for any key that can be processed by KeyPress.

If you put a breakpoint in the KeyPress, you will see the Enter key come thru even if e.Handled was set in KeyDown.

You set e.Handled in KeyPress to stop the beep.

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Ok, I tried this, but I still get the beep sound. I set e.Handled to true in the KeyPress event; however, I still got the beep. Is there more to it then this?

Thanks,
-bitwise
 
Back in VB6 the answer was to set the keycode to zero, don't know if that would work ?
e.KeyCode = 0
 
This is what we did. Another simple approach, but not a great one is placing an invisible button in your form and setting that as the AcceptButton of the form.

-Kris

 
Thanks guys. The code definitely has to be in the KeyPress event and not in the KeyDown event. Then you just have to do this:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If TextBox1.Text <> [String].Empty Then
If e.KeyChar = System.Convert.ToChar(13) Then
' do whatever
e.Handled = True
End If
End If
End Sub

Thanks again!
-bitwise
 
Ok, you don't need that line, that is for my own use. Notice the "' do whatever" comment in the above code snippet? It has something to do with something else I'm doing.

-bitwise
 
Heeeelp!!!

There is a beep whenever i press enter at a textbox..
how can i get rid of it...

Here is my code.. hope anyone knows..

thanks in advance guys....

Private Sub txtfrecval_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtfrecval.KeyDown
If e.KeyCode = Keys.Enter Then
txtvalfrec.Focus()
e.Handled = True
End If
End Sub
Private Sub txtvalfrec_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtvalfrec.KeyDown
If e.KeyCode = Keys.Enter Then
Me.frecuencias()
txtfrecval.Clear()
txtvalfrec.Clear()
txtfrecval.Focus()
e.Handled = True
End If
End Sub
 
Code has to be handled in the KeyPress event...and not the KeyDown event. That should do it.

-bitwise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top