Results 1 to 6 of 6

Thread: [RESOLVED] [2008] Stop Beep sound when pressing Enter on TextBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    15

    Resolved [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

  2. #2

  3. #3
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  5. #5
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2008] Stop Beep sound when pressing Enter on TextBox

    Oh wow, yet again I failed. Completly misread the question.

    sorry!

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    15

    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:
    1. Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    2.         If e.KeyCode = Keys.Enter Then
    3.             e.SuppressKeyPress = True
    4.             Me.TextBox2.Select()
    5.         End If
    6.     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
  •  



Click Here to Expand Forum to Full Width