So you can easily do that using keyboard only. To do this, you have to write a very simple code.
You can switch cursor from one textbox to another, by pressing Enter button or by pressing Tab or by pressing any other key of the keyboard. For every cases, just one line will be changed among the entire code. So now lets go to start our work.
I present an example here for you to understand easily. Suppose, there is a form where I have two textbox under Name and City. Let, the cursor is in the textbox under Name. It appears like this:
I write in the Name field a sample name like Arif and then click Enter. Then the output must be like this i.e. the present cursor will be switched to textbox under City. It appears like this:
Now what about the code? If you choice to click Enter then the following code will be needed to be added under KeyDown Event:
Private Sub txtName_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtName.KeyDown
If e.KeyCode = Keys.Enter Then
txtCity.Focus()
End If
End Sub If e.KeyCode = Keys.Enter Then
txtCity.Focus()
End If
Here txtName is the name of the first textbox and txtCity is the name of the second textbox.
If you want to use the key F1 in lieu of Enter, you have to just place F1 for Enter. It will be like this:
Private Sub txtName_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtName.KeyDown
If e.KeyCode = Keys.F1 Then
txtCity.Focus()
End If
End Sub If e.KeyCode = Keys.F1 Then
txtCity.Focus()
End If
0 comments:
Post a Comment