|
-
Aug 11th, 2007, 03:04 PM
#1
[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!
-
Aug 12th, 2007, 01:59 AM
#2
Frenzied Member
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
-
Aug 21st, 2007, 09:48 AM
#3
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...
-
Aug 21st, 2007, 09:57 AM
#4
Frenzied Member
Re: Enter clicks a default button
Hi,
try
Code:
btngo_click(me, system.eventargs.empty)
from memory 
Pete
-
Aug 21st, 2007, 10:42 AM
#5
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.
-
Aug 21st, 2007, 11:39 AM
#6
Frenzied Member
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
-
Aug 22nd, 2007, 07:05 AM
#7
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|