Results 1 to 15 of 15

Thread: [RESOLVED] [2005] Form KeyUp Enter key beeping

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [RESOLVED] [2005] Form KeyUp Enter key beeping

    I've got this code:

    Code:
        Private Sub APC_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
            If e.KeyCode = Keys.Enter Then
                Call ButtonGo()
            End If
            e.Handled = False
        End Sub
    I've got KEYPREVIEW set as true for the form - so that pressing the ENTER key will cause this event to fire and then process the same sub that clicking the GO button does as well.

    I cannot get the ENTER key to stop beeping. I've tried the e.Handled=True and =False (the help says that Handled means different things to different UI objects.

    At any rate - I do not want the ENTER key to make a beep.

    Note that I'm on a pocket PC - but I don't think that will make a difference.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] Form KeyUp Enter key beeping

    Does it still do it if you;

    Code:
            If e.KeyValue = Keys.Return Then
                e.Handled = True
            End If

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Form KeyUp Enter key beeping

    Try
    Code:
    If Asc(e.KeyChar) = Keys.Enter Then
    Thats what I use and I don't get any beeping.

    However, I'm not on a pocket PC.

  4. #4

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Form KeyUp Enter key beeping

    I changed it to this:

    Code:
        Private Sub APC_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
            If e.KeyCode = Keys.Return Then
                'Call ButtonGo()
                e.Handled = True
            End If
        End Sub
    and it still beeps.

    Of course my button function isn't being called - but yes it is still beeping.

    It does not beep if I type letters on the keyboard - it's just the ENTER/RETURN key that's doing it.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Form KeyUp Enter key beeping

    Maybe it is the pocket PC.

    Do you run similiar code on a desktop or laptop?

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Form KeyUp Enter key beeping

    Quote Originally Posted by Hack
    Try
    Code:
    If Asc(e.KeyChar) = Keys.Enter Then
    Thats what I use and I don't get any beeping.

    However, I'm not on a pocket PC.
    Either KEYCHAR is not part of the CF or it's not in the KEYUP event...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Form KeyUp Enter key beeping

    I didn't notice you were using KeyUP.

    Try KeyPress instead.

  8. #8

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Form KeyUp Enter key beeping

    Yeah - this did get rid of the beep:

    Code:
        Private Sub APC_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
            If Microsoft.VisualBasic.Asc(e.KeyChar) = Keys.Enter Then
                Call ButtonGo()
                e.Handled = True
            End If
        End Sub
    Using the KEYPRESS and making sure to have the HANDLED=TRUE

    Why is this?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Form KeyUp Enter key beeping

    The beep occurs when the key is pressed. It's too late by the time the KeyUp event is raised. If you press and hold the Enter key you get one KeyDown event and multiple KeyPress events, which would lead to multiple beeps (I think, although I can't test because my work rig has no speakers). When you release the key you get one KeyUp event and no more beeps.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [2005] Form KeyUp Enter key beeping

    This is the solution:

    Code:
        Private Sub APC_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
            e.Handled = False
            If Microsoft.VisualBasic.Asc(e.KeyChar) = Keys.Enter Then e.Handled = True
        End Sub
    
        Private Sub APC_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
            If e.KeyCode = Keys.Return Then
                Call ButtonGo()
            End If
        End Sub
    Handled has to be managed from the KeyPress event. This allows any key to still be entered on the keyboard (remember this is a ppc - but it still has a graphical keyboard image).

    I personally am against firing functions and subs from KeyPress - as KeyPress cannot be trusted to only occur one time for a key being clicked.

    So I'm processing my ButtonGo() function in the KeyUp event.

    There is no beep with this logic.

    And the ButtonGo() function is not fired until I take the pin off the PPC screen. As long as I'm still pushing the ENTER key with the pin nothing happens - it's when I let go.

    Thanks for all for the info that got me to this point.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] [2005] Form KeyUp Enter key beeping

    Just yesterday I was wondering how you would use Microsoft.VisualBasic an lo and behold, and example appears.
    Code:
    If Microsoft.VisualBasic.Asc(e.KeyChar) = Keys.Enter Then e.Handled = True
    In my KeyPress events I am just using
    Code:
    If Asc(e.KeyChar) = Keys.Enter Then
    I'm curious as to why you prefaced your code with Microsoft.VisualBasic

  12. #12

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] [2005] Form KeyUp Enter key beeping

    Quote Originally Posted by Hack
    ...I'm curious as to why you prefaced your code with Microsoft.VisualBasic
    Otherwise I have to IMPORT the namespace at the top of the app - right? I'm new to this .Net...

    Maybe someone can shed some light on the differences between IMPORT of the namespace and this long-name reference. Does the namespace get fully imported anyway?

    I was against using the ASC() function at all - almost felt like simply building a constant of the value 13!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] [2005] Form KeyUp Enter key beeping

    The only imports I'm using are for Excel and SqlClient

  14. #14

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] [2005] Form KeyUp Enter key beeping

    Quote Originally Posted by Hack
    The only imports I'm using are for Excel and SqlClient
    Then it's a pocket pc thing - the compact framework has much less girth - as the PPC is a small device.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] [2005] Form KeyUp Enter key beeping

    Ok, that makes sense.

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