Changing Character Entered

  • Thread starter Thread starter Ricky W. Hunt
  • Start date Start date
R

Ricky W. Hunt

Is there is a way to "change" what character the user typed? For instance,
is there anything I can put in a Keypress handler that if the user pressed
the <Enter> key it make it appear to the program that <Tab> was pressed? I'm
going through some tutorials that has a number validation routine (to ensure
only numbers were pressed, etc.) and it has a check to see if the <Enter>
key was pressed, and if so to set the focus to the next text box. Since
there's a bunch of these text boxes this code has to be copied into then
Keypress handler for each one. A subroutine won't work because the box you
want to transfer focus on depends on which box you are currently in. I
thought if I could make it appear to the program as though the user had
pressed Tab when they pressed Enter the cursor would jump to the correct box
(as set up by Tab order) and therefore I'd have a "universal" subroutine
that could be used for all the boxes.
 
Well firstly, there are two ways to handle this situation. You could create
a handler for the first text box and then add more handles statements for
all the others you want this sub to handle ( 1 sub, handles all your txt
boxes. ), or you can set the form to Preview in the properties, and check
the keypress event for the form, this way you will trap all kepress events
and the form previews them before passing them on the handler for the
control that called them.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
One Handed Man ( OHM - Terry Burns ) said:
Well firstly, there are two ways to handle this situation. You could create
a handler for the first text box and then add more handles statements for
all the others you want this sub to handle ( 1 sub, handles all your txt
boxes. ), or you can set the form to Preview in the properties, and check
the keypress event for the form, this way you will trap all kepress events
and the form previews them before passing them on the handler for the
control that called them.

Yes but how does the one sub know where to put the focus next? It doesn't
seem like I should have to write a Case statement with the sub for each box
just to set focus. Why isn't here some "generic" command that just says "set
focus to the next control according to tab order" or something to that
effect?
 
Easy . . . In each handler or in the form's keypress with KepPreview to on

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = ChrW(Keys.Return) Then
SendKeys.Send("{TAB}")
End If
End Sub


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
One Handed Man ( OHM - Terry Burns ) said:
Easy . . . In each handler or in the form's keypress with KepPreview to on

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = ChrW(Keys.Return) Then
SendKeys.Send("{TAB}")
End If
End Sub

Thanks. That's what I was asking for (but didn't know how to phrase it). In
other words, "how do I load the keyboard buffer to make it look like the
user hit such-and-such key". I will look into SendKeys. Thanks again.
 
Back
Top