Keys.Return - Strange Problem...

A

Aaron

Why is this happening...In both text boxes I have the same code for
the KeyDown event but when I'm in the txtEndMiles box (in other words
it has the focus) and press the center button, or enter button, it
throws the cursor in the txtStartMiles and executes the Keys.Return
section...why?

Private Sub txtStartMiles_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtStartMiles.KeyDown
If e.KeyCode = Keys.Up Then
If txtEndMiles.Focus Then
txtStartMiles.Focus()
Else
txtStartMiles.Focus()
End If
End If
If e.KeyCode = Keys.Down Then
If txtStartMiles.Focus Then
txtEndMiles.Focus()
Else
txtStartMiles.Focus()
End If
End If
If e.KeyCode = Keys.Return Then
If txtStartMiles.Focus Then
Dim numPad As New frmNumPad

numPad.txtEntry.Text = Me.txtStartMiles.Text
numPad.Text = "Route Tracker"
Me.Text = ""
numPad.Show()
ElseIf txtEndMiles.Focus Then
Dim numPad As New frmNumPad

numPad.txtEntry.Text = Me.txtEndMiles.Text
numPad.Text = "Route Tracker"
Me.Text = ""
numPad.Show()
End If
End If
End Sub
 
D

Daniel Moth

I am not looking at this code in any detail (it is not part of a
reproducible sample) but...

....you say that the same code runs for KeyDown of both textboxes but I only
see txtStartMiles after Handles

....you have the txtXX.Focus() method in conditions; did you mean to use the
Focused property?

Cheers
Daniel
 

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

Similar Threads


Top