VB3 Making ENTER Key Move Focus Like TAB Key for VB ControlsID: Q85562
|
You can cause the ENTER key to move the focus to the control with the
next higher TabIndex property value, as the TAB key does.
However, using the Enter key to move the focus does not follow recommended
Windows-based application design guidelines. The Enter key should be used
to process the default command or to process entered information, not to
move the focus.
You can detect when the user presses ENTER from the KeyPress event
procedure by checking to see if the KeyAscii parameter is the
character code for ENTER (13). Then you can move the focus to the next
control in the TabIndex order with SendKeys "{tab}". You can move
the focus to the previous control with SendKeys "+{tab}".
This technique works with most kinds of controls. It does not work
with command button controls, because command buttons do not receive
the KeyPress event when you press ENTER.
Sub Text1_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then ' The ENTER key.
SendKeys "{tab}" ' Set focus to next control.
KeyAscii = 0 ' Ignore this key.
End If
End Sub
Sub Text2_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then ' The ENTER key.
SendKeys "{tab}" ' Set focus to next control.
KeyAscii = 0 ' Ignore this key.
End If
End Sub
Additional query words: 2.00 3.00 return key
Keywords : kbcode PrgCtrlsStd
Version : 1.00 2.00 3.00
Platform : WINDOWS
Issue type :
Last Reviewed: June 21, 1999