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:

VB.NET:
    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
 
set
e.SuppressKeyPress = True

after you change the text, should do the trick
 
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..
 

Latest posts

Back
Top