Return Key as Tab

V

Vinay

Hi,

Can I enforce Return key to behave like a TabKey ?

I am using the following KeyPress down event for my
control:

Private Sub Navigate(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs)

Try
Select Case e.KeyChar
Case vbCrLf
e.Handled = True
'CType(sender, TextBox).Focus()
End Select

Catch oEX As Exception
Call MsgBox(oEX.Message)
Finally

End Try
End Sub
 
E

EricJ

i had the same prob a while back, so ill give to you w others in this ng
gave to me :)

Turn "KeyPreview ON" for the form before your try this code:


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

If e.KeyCode = Keys.Enter Then
If Not ActiveControl Is Nothing Then
SendKeys.Send("{TAB}")
End If
End If

End Sub
 
C

Cor

Hi vinay,

Is there any reason why you does not do?

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e _
As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select case e.keysdata
case Keys.Enter
Private Sub Navigate(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs)

Try
Select Case e.KeyChar
Case vbCrLf
e.Handled = True

I am curious?

Cor
 
F

Fergus Cooney

Hi Vinay,

The 'sender' parameter in Navigate() will always be the Form itself, so it
won't be of much use to you.

Have a play with
Control.GetNextControl (Me.ActiveControl, True).Focus

Regards,
Fergus
 
F

Fergus Cooney

Good morning Cor,

Just a wee note - Did you know that you can do

Private Sub Navigate(ByVal sender As Object, _

ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown

'Deal with <Enter>, <Arrows>, etc

<and>

Private Sub Form1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown

'Deal with other keys

This is because MyBase.KeyDown is a multicast Delegate - they will <both>
fire for the KeyDown Event. (Also the names of the Subs don't matter).

Regards,
Fergus
 
C

Cor

Hi Herfried,
Notice that 'DirectCast' should be used instead of 'CType' in this case.

Not "should", Fergus did notice you about that, it has a different meaning
than in the equivalent in the German language.

"could be better used" I thought it was.

Cor
 
E

EricJ

since i started meddeling ;p

should gives the impression that it will not work unless you do it

yust a note (i dont want to start a war here ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top