Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1539

check vb6 textbox press tab on keybode

$
0
0
when press tab,it will lostfocus,how to stop it,hook it ,i need do other action

Task completed, found 3 solutions

Code:

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Boolean


Private Sub Text2_Validate(Cancel As Boolean)
Debug.Print "Text2_Validate"
If GetKeyState(vbKeyTab) Then
If it is detected that the Tab has been pressed, it will prevent losing focus
Cancel = True
Debug.Print "Cancel Tab by Validate"
End If
   
'Text2_Validate
'Cancel Tab by Validate
Will not trigger the Text_2LostFocus event
End Sub

Code:

Private Sub Text2_LostFocus()
  Debug.Print "Text2_LostFocus"
  If GetKeyState(vbKeyTab) < 0 Then
        Debug.Print "vbKeyTab Pressed"
        Text2.SetFocus 'STOP TAB Action/Cancel Do Press Tab
  End If
 
'    Text2_LostFocus
'    vbKeyTab Pressed
'    Text3_GotFocus
'    Text2_GotFocus
End Sub

Code:

Private Sub Text3_GotFocus()
    Debug.Print "Text3_GotFocus"
  If GetKeyState(vbKeyTab) < 0 Then
        Debug.Print "vbKeyTab Pressed"
        Text2.SetFocus 'STOP TAB Action/Cancel Do Press Tab
  End If
End Sub

question:https://www.vbforums.com/showthread....tab-on-keybode

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>