Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello!

 

When you execute a program, you can automatically move from one button to the other with the Up and Down arrows of keypad.

 

Now I want to move from a textbox to the other with the Up and Down arrows (which is not automatic).

 

I have this code which can be used with the Keypress event if you know the ascii code of the key :

 

Public Function KeyAscii(ByVal UserKeyArgument As KeyPressEventArgs) As Short

KeyAscii = Asc(UserKeyArgument.KeyChar)

End Function

 

But the Up and down arrows seem to have no ascii code...

 

Now do you have another solution to this problem??

  • Leaders
Posted

you cant move from a textbox to another with the Up and Down arrows ( that will just do the same as left and right , move through the text )

but you can do this :

   Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
       If e.KeyCode = Keys.Down Then
           TextBox2.Focus()
       End If
   End Sub

   Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp
       If e.KeyCode = Keys.Up Then
           TextBox1.Focus()
       End If
   End Sub

hope it helps.

Posted

Thank you, it helps very much!

 

Just a question about this code : how come that if i go down from textbox1 to textbox2 and if there is text in textbox2, the cursor doesn't go automatically to the end of the text (it goes in the middle of the text)

  • Leaders
Posted

if there is text in a textbox you can use the SelectionStart property , eg:


Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
       If e.KeyCode = Keys.Down Then
           TextBox2.Focus()
           TextBox2.SelectionStart = Len(TextBox2.Text) '// go to end of text.
       End If
End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...