PDA

Click to See Complete Forum and Search --> : [RESOLVED] Enter clicks a default button


szlamany
Aug 11th, 2007, 03:04 PM
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!

petevick
Aug 12th, 2007, 01:59 AM
Hi,
allow keypreview on the form, and check for the enter key presses, and then programatically click your button

Pete

szlamany
Aug 21st, 2007, 09:48 AM
How do I programmatically click the button??

I've got this so far:

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

petevick
Aug 21st, 2007, 09:57 AM
Hi,
try
btngo_click(me, system.eventargs.empty)
from memory :)

Pete

szlamany
Aug 21st, 2007, 10:42 AM
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:

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 SubThe 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.

petevick
Aug 21st, 2007, 11:39 AM
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=UTF-8&q=group%3A*dotnet*+beep+textbox

Pete

szlamany
Aug 22nd, 2007, 07:05 AM
This ended up being the final solution - worked out on the .Net forum in this thread: http://www.vbforums.com/showthread.php?&t=485046&is_resolved=1

From that thread:

This is the solution:

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.