Results 1 to 8 of 8

Thread: [RESOLVED] [VB2010] - how avoid the beep, changing the control focus with return key?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Resolved [RESOLVED] [VB2010] - how avoid the beep, changing the control focus with return key?

    i have these code for change the control focus:
    Code:
    Private Sub txtMatricula_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtMatricula.KeyUp
            If e.KeyCode = Keys.Return Then
                Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
                e.Handled = False
            End If
        End Sub
    but i always ear 1 beep
    can i avoid it?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Re: [VB2010] - how avoid the beep, changing the control focus with return key?

    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - how avoid the beep, changing the control focus with return key?

    Quote Originally Posted by kebo View Post
    sorry seems:
    e.SuppressKeyPress = True
    isn't resolved, i use it with keyup event.. the beep continues
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [VB2010] - how avoid the beep, changing the control focus with return key?

    Have you tried exactly like so? Below:

    Code:
    Private Sub TxtBox_Keydown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TxtBox.Keydown
            If e.KeyCode = Keys.Enter Then
                e.SuppressKeyPress = True
        'Do more mad stuff
            End If
        End Sub
    Last edited by Mucker; Jan 26th, 2014 at 05:12 PM.

  5. #5
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Re: [VB2010] - how avoid the beep, changing the control focus with return key?

    Quote Originally Posted by joaquim View Post
    sorry seems:
    e.SuppressKeyPress = True
    isn't resolved, i use it with keyup event.. the beep continues
    That's because the beep occurs on the key down, not the keyup.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - how avoid the beep, changing the control focus with return key?

    after more tests i found the problems and solutions:
    1 - these code works fine with keydown event:

    Code:
    If e.KeyCode = Keys.Return And e.Alt = False Then
                e.SuppressKeyPress = True 'make sure the key is pressed only 1 time and avoid the beep
                Me.SelectNextControl(Me.ActiveControl, True, True, True, True) 'these line moves the focus to the next control, by tab order
            End If
    2 - by some reason don't use the keyup event;

    3 - if what only some controls for the return key do the job, just use on all controls you need. if you need use for all controls, use the keydown event from the form;

    4 - if you use the form, never forget activate the KeyPreview property.

    5 - imagine that you need a newline on text boxes, you can test with alt key.

    Code:
    Private Sub txtReparacoesNecessarias_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtReparacoesNecessarias.KeyDown
            If e.KeyCode = Keys.Return And e.Alt = True Then
                e.SuppressKeyPress = True
                txtReparacoesNecessarias.SelectedText = txtReparacoesNecessarias.SelectedText + vbNewLine
            End If
        End Sub
    i hope these information helps others readers
    Last edited by joaquim; Jan 26th, 2014 at 05:28 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: [VB2010] - how avoid the beep, changing the control focus with return key?

    Quote Originally Posted by kebo View Post
    That's because the beep occurs on the key down, not the keyup.
    Well it's only 2 words of code to fix it. Handler and sub name renaming. Your reply made my desk hit me in the face. (I thought it was on both for a second, but then realized why would i only disable it on one handle?) :P Think they call that desk palm.
    Last edited by Mucker; Jan 26th, 2014 at 05:20 PM.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [RESOLVED] [VB2010] - how avoid the beep, changing the control focus with return

    what you 2 think about that information that i tested with your, both, help?
    VB6 2D Sprite control

    To live is difficult, but we do it.

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