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

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

Question 1: How to use the Listview control as an Excel spreadsheet in VB6, where you can click to modify the values of each row and column. Add a text box, press the Tab key to automatically display the text of each cell, and wrap lines automatically.
Question 2: VB6 checks if the text box has pressed TAB, interrupts and executes other code

Tag keywords: vb6, tab keyboard detection, Listview editing, Excel

For example, adding a Text1 text box on the Listview control to edit data for each cell in multiple rows, pressing Tab may cause text1 to lose focus, and Listview or other controls may have gained focus.
Requirement: When pressing Tab, prevent other controls from getting focus, such as automatically obtaining the data of the next cell and selecting all, directly entering content to modify, or manually clicking the mouse to modify some text. Continuing to press TAB will continuously switch between displaying the contents of different cells, automatically wrapping until the last row and the last cell, prompting "All data has been processed"

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 1449

Trending Articles



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