Question Windows Beeps when Key Combination entered

ibby

Member
Joined
Jul 30, 2011
Messages
7
Programming Experience
3-5
Hello,
I am working on a program in which I allow the user to quickly add strings to a textbox by pressing a key combination, such as ALT+S. Inserting the strings and setting the cursor to the right position works fine. Its just that windows makes an annoying beep as if an error was encountered every time I press the key combination. I am using the KeyDown event to handle the keystrokes, and I have tried e.Handled = True - without success. Here's a bit of code to give you the idea:

Code:
    Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        Dim CursorPosition As Integer = TextBox1.SelectionStart
        If e.Alt And e.KeyCode = Keys.S Then
            TextBox1.Text = TextBox1.Text.Insert(CursorPosition, "sin(")
            TextBox1.SelectionStart = CursorPosition + 4
        End If
        ' Same kind of If statements continue here.
    End Sub
Thanks for helping out!
Ibby
 

Flippedbeyond

Well-known member
Joined
Dec 19, 2008
Messages
198
Programming Experience
1-3
set
e.SuppressKeyPress = True

after you change the text, should do the trick
 

ibby

Member
Joined
Jul 30, 2011
Messages
7
Programming Experience
3-5
set
e.SuppressKeyPress = True

after you change the text, should do the trick
Thanks, worked like a charm :) Makes sense as well, the event just bubbled up to the form which made the noise..
 
Top Bottom