A simple example, how to use feature of TAB key using ENTER key in vb
Generally TAB key is used for getting focus on next object/control within form. The object / control can be textbox, command button, combo box or anything that you place on form.
So here we are using Enter key to work as a TAB key.
you may use any key to work as a TAB key if you know the ascii value of that key.
First of all,
-> Place 2 -3 textbox in your form.(You can place any control from design view)
->Now Double click on any of that textbox, after double clicking, you may be in Change event of that textbox.
->now change to keypress event, this will look like this.
Private Sub your_textbox_KeyPress(KeyAscii As Integer)
End Sub
->Now copy below code and paste between that two line.
If KeyAscii = 13 Then ' The ENTER key.
SendKeys "{tab}" ' Set the focus to the next control.
KeyAscii = 0 ' Ignore this key.
End If
->that will look like this
Private Sub your_textbox_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then ' The ENTER key.
SendKeys "{tab}" ' Set the focus to the next control.
KeyAscii = 0 ' Ignore this key.
End If
End Sub
Here whenever any key is pressed within particular object/control, the KeyPress event will be called of that object.
Keypress event will check whether key pressed is Enter key(Ascii value is 13) or not.
if it is Enter key means ascii value is 13 then it will send control to the Tab key and Enter key will be ignored.
So whenever you press Enter Key, your Enter key will work as a Tab key.
so you will get focus on next object.
you may use any key to work as a TAB key if you know the ascii value of that key.
Generally TAB key is used for getting focus on next object/control within form. The object / control can be textbox, command button, combo box or anything that you place on form.
So here we are using Enter key to work as a TAB key.
you may use any key to work as a TAB key if you know the ascii value of that key.
First of all,
-> Place 2 -3 textbox in your form.(You can place any control from design view)
->Now Double click on any of that textbox, after double clicking, you may be in Change event of that textbox.
->now change to keypress event, this will look like this.
Private Sub your_textbox_KeyPress(KeyAscii As Integer)
End Sub
->Now copy below code and paste between that two line.
If KeyAscii = 13 Then ' The ENTER key.
SendKeys "{tab}" ' Set the focus to the next control.
KeyAscii = 0 ' Ignore this key.
End If
->that will look like this
Private Sub your_textbox_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then ' The ENTER key.
SendKeys "{tab}" ' Set the focus to the next control.
KeyAscii = 0 ' Ignore this key.
End If
End Sub
Here whenever any key is pressed within particular object/control, the KeyPress event will be called of that object.
Keypress event will check whether key pressed is Enter key(Ascii value is 13) or not.
if it is Enter key means ascii value is 13 then it will send control to the Tab key and Enter key will be ignored.
So whenever you press Enter Key, your Enter key will work as a Tab key.
so you will get focus on next object.
you may use any key to work as a TAB key if you know the ascii value of that key.
No comments:
Post a Comment