Jump to content

ComboBox + Windows Error "Ding!" Sound

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
TommyRay

TommyRay

    Newbie

  • Members
  • Pip
  • 2 posts
Greets!

I have been perplexed by trying to use a ComboBox in a DropDown style for a Web browser app. There is this very annoying DING! sound (Windows system error sound) when pressing enter.

I have tried a few suggestions to no avail. I am using VS 2008.

This does not affect it when changing the style but I need the DropDown in order to make and save a "history" of sites visited.

I'd like to find a solution, if anyone has any ideas? Thanks! Here is something I have been trying...


    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown

        Dim objcboBox As New ClasscboBox

        objcboBox.KeyDown(objcboBox, New KeyEventArgs(Keys.Enter))

        If e.KeyCode = Keys.Enter Then

            ComboBox1.Items.Add(ComboBox1.Text)

            WebBrowser1.Navigate(ComboBox1.Text)

            Me.Text = (ComboBox1.Text)

            'SaveHistory()

            e.Handled = True ' <- This keypress has been handled, no more processing for that

        End If

    End Sub



ublic Class ClasscboBox

    Inherits ComboBox


    Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)

        If e.KeyChar = ControlChars.Cr Then

            e.Handled = True

        Else

            MyBase.OnKeyPress(e)

        End If

    End Sub 'OnKeyPress


    Public Shadows Sub KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)

        If e.KeyCode = Keys.Enter Then ' Enter could be trapped in KeyDown event

            e.Handled = True

        Else

            MyBase.OnKeyDown(e)

        End If

    End Sub 'KeyDown


End Class


-Tom

#2
TommyRay

TommyRay

    Newbie

  • Members
  • Pip
  • 2 posts

    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown

        If e.KeyCode = Keys.Enter Then

            e.SuppressKeyPress = True

        End If

    End Sub



    Private Sub ComboBox1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles ComboBox1.PreviewKeyDown

        If e.KeyCode = Keys.Enter Then

            ' User pressed Enter. Save the text user typed, open url or whatever

            ' Enter-key passes through and will be suppressed in KeyDown event handler

        End If

    End Sub


Solution given by Teme64 elsewhere. Hope this helps someone else as I had wracked my brain on it for weeks! :)