Results 1 to 7 of 7

Thread: [RESOLVED] Enter clicks a default button

  1. #1

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

    Resolved [RESOLVED] Enter clicks a default button

    This is probably a general .Net question - sorry...

    I have a button on my PPC form that basically runs whatever you just type into a textbox. Clicking that button with the pin fires the event.

    How do I make it so clicking ENTER on the keyboard image with actually click this button. There is no DEFAULT property like VB6 had.

    Thanks!

    *** 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
    Oct 2005
    Posts
    1,286

    Re: Enter clicks a default button

    Hi,
    allow keypreview on the form, and check for the enter key presses, and then programatically click your button

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

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

    Re: Enter clicks a default button

    How do I programmatically click the button??

    I've got this so far:

    Code:
       Private Sub APC_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
            If CType(e.KeyChar.CompareTo(Keys.Return), Boolean) Then
                btnGo. <-- what goes here to click the btnGo button?
            End If
        End Sub
    actually - the Compare to is blowing up as well - I found that in a post by RobDog...

    *** 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

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Enter clicks a default button

    Hi,
    try
    Code:
    btngo_click(me, system.eventargs.empty)
    from memory

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5

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

    Re: Enter clicks a default button

    Thanks - that actually did work...

    I decided to take the button event code and put it into a separate sub - as suggested by JMC in other threads.

    I now have this:

    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
        End Sub
    The ButtonGo() function is called by this event and also the real "click" event.

    I decided to use KEYUP as KEYPRESS was not working well for my with checking for the ENTER key.

    Now the only other problem I seem to have is that if I use the ENTER key I hear a BEEP - but I do not hear that BEEP when I click the button.

    *** 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

  6. #6
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Enter clicks a default button

    Hi,
    do you want to stop beep when you press enter, or beep when you programatically press enter?
    If the former, try 'e.handled = true' after 'call buttongo()'.
    If the latter, you would have to play the beep sound I think.

    http://groups.google.com/groups?ie=U...*+beep+textbox

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  7. #7

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

    Re: Enter clicks a default button

    This ended up being the final solution - worked out on the .Net forum in this thread: http://www.vbforums.com/showthread.p...&is_resolved=1

    From that thread:

    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.

    *** 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

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