-
Apr 18th, 2015, 02:21 AM
#1
Thread Starter
Fanatic Member
Disable Tab on TextBox
Hi
I have textbox i want that when user press Tab or Enter Key it should perform same task
Thanks
Last edited by Jagjit; Apr 18th, 2015 at 02:31 AM.
-
Apr 18th, 2015, 02:25 AM
#2
Re: Disable Tab on TextBox
I think it's Test1.TabStop = True then when user presses Enter set Text1.TabStop = False if I understand your question
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Apr 18th, 2015, 03:22 AM
#3
Re: Disable Tab on TextBox
You can use the KeyPress events:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0 ' avoid the beep when Enter key is pressed
SendKeys "{TAB}"
End If
End Sub
This move the focus to the next control, based on the value of TabIndex property
-
Apr 18th, 2015, 03:23 AM
#4
Re: Disable Tab on TextBox
If you set all 'focus able' controls on a form to have a .Tabstop = False property, you can control your textbox's tab key input using the KeyPress event without needing to dive to deep into hooking or bypassing normal win forms behavior.
Code:
'Make sure other "focusable" controls on the same form have .Tabstop = False or this won't work with they tab key.
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii = vbKeyTab) Or (KeyAscii = vbKeyReturn) Then
KeyAscii = 0
'the things i want both ENTER and TAB will do
End If
End Sub
gibra above beat me to it, although i must add that using SendKeys is really not a good practice, it is known to be very unreliable and should be avoided.
Last edited by stum; Apr 18th, 2015 at 03:26 AM.
-
Apr 18th, 2015, 04:27 AM
#5
Thread Starter
Fanatic Member
Re: Disable Tab on TextBox
Hi
I am getting runtime error . Permission Denied. Below is the code
If (KeyAscii = vbKeyReturn) Then
Set rsfind = New ADODB.Recordset
If rsfind.State = 1 Then rsfind.Close
rsfind.Open "select * from tblmembers where student_id = '" & Trim(txtstudentid.Text) & "'", cnn1, adOpenStatic, adLockOptimistic, adCmdText
If rsfind.RecordCount = 0 Then
MsgBox "Student ID Does Not Exists !", vbCritical
txtstudentid.Text = ""
txtstudentid.SetFocus
cmdbook.Enabled = False
Else
txtstudentname = rsfind!firstname & " " & rsfind!middlename & " " & rsfind!lastname
cmdbook.Enabled = True
cmdbook.SetFocus
End If
KeyAscii = 0
SendKeys "{TAB}"
End If
Originally Posted by gibra
You can use the KeyPress events:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0 ' avoid the beep when Enter key is pressed
SendKeys "{TAB}"
End If
End Sub
This move the focus to the next control, based on the value of TabIndex property
-
Apr 18th, 2015, 06:52 AM
#6
Hyperactive Member
Re: Disable Tab on TextBox
Originally Posted by Jagjit
I am getting runtime error . Permission Denied.
It's becase of SendKeys command. Instead of that, use this.
-
Apr 18th, 2015, 07:49 AM
#7
Re: Disable Tab on TextBox
Why not just forget this and live with the intended behavior? Trying to change how user interfaces work in Windows to something bizarre is a mistake.
Enter key actions only have two meanings: in a multiline control they mean "newline" and everywhere else they mean "activate the default control." This is similar to the ESC key triggering the control marked as the cancel control.
Most of this is covered in Keyboard:
Default buttons. Windows with command buttons and command links have a single default button indicated by a highlighted border, which is the button that is clicked when the Enter key is pressed. There is a single default command button or command link assigned by default. However, the default button moves when the user tabs to another command button or command link. Consequently, any command button or command link with input focus is also always the default button.
The OK button is normally the default button, as indicated by its highlighted border. However, if the user were to tab to the Cancel button, it would become the default button and would be activated with the Enter key.
Spacebar, Enter, and Esc keys. The spacebar activates the control with input focus, whereas the Enter key activates the default button. Pressing the Esc key cancels or closes the window.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|