954,124 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

enter key

Hello :)

Iam using windows application, I want to know how can I move from textbox1 to textbox2 through the tab control key or enter key..

vb_learner
Newbie Poster
13 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

or you could just use the mouse and position the cursor in which ever text box you want?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Try this:

Private Sub TextBox1_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown
        If e.KeyCode = Keys.Tab Then
            If sender.Name = "TextBox1" Then
                TextBox2.Focus()
                e.Handled = True
            ElseIf sender.Name = "TextBox2" Then
                TextBox1.Focus()
                e.Handled = True
            End If
        End If
    End Sub

 Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            If sender.name = "TextBox1" Then
                TextBox2.Focus()
                e.Handled = True
            ElseIf sender.name = "TextBox2" Then
                TextBox1.Focus()
                e.Handled = True
            End If
        End If
    End Sub
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

1)the tab works by default right?

2)I added the enter code but still when i start my program the focus is always at the 2nd text box, so what can i do?
3) can i move between textboxes using the ASCII code 13? how?
thanks : )

vb_learner
Newbie Poster
13 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

You don't want to do this. The "enter" key is universally used to submit a form, or perform a default action. Altering it is a major violation of the User Model.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

sorry but i didn't understand ;/ ,,
what i meant is using enter key to move from one text box to another..
and how I can do it..

I'm very new to programming. . :)

vb_learner
Newbie Poster
13 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 
sorry but i didn't understand ;/ ,, what i meant is using enter key to move from one text box to another.. and how I can do it.. I'm very new to programming. . :)

In the GUI tab there should be an option in the text box to enable or disable the tab key. If it is disabled you should be able to use it to go through different buttons and text fields.

But using enter to do the same would be frowned upon.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

see attachment

Attachments crap.GIF 24.97KB
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

now that i have 3 text boxes .. when i type numbers then press enter the numbers will be cleared??
and that doesn't happen with 2nd and 3rd number?

vb_learner
Newbie Poster
13 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

Huh?

When you press the enter button on the keyboard you mean.

Do you have any code?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

well,
lets say i have 3 textboxes, i entered a value in the 1st box then i press enter, the value will disappear
then the cursor will move to the 2nd box, but the value i type in it doesn't disappear?

Case 13
If sender Is txtA1 Then
txtA2.Focus()
ElseIf sender Is txtA2 Then
txtA3.Focus()
Elseif sender Is txtA3 
txtA1.focus()
End If
vb_learner
Newbie Poster
13 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

Disappear?

To clear a txt box I just use:

txtBox.Text = ""  'Clear text field
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

I agree with iamthwee! You should not use the enter for simple textbox navigation. Hitting the enter key is like hitting "finished" for having it as anything but submit is a big faux pas. You should set it up with tab. Click on the texbox and open the properties window. Use TabStop to enable or disable it in the tab order. Use "TabIndex" to give it a tab number, 1's the first 2's the second and so on.

I would not use enter if I was you cause if anyone was to use the program they'd fill in the blanks hit enter just to see focus change. They'll be confused.

Rasb

Rasb23
Newbie Poster
1 post since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You