PDA

Click to See Complete Forum and Search --> : VB - A demonstration of how to trap the Tab key


MartinLiss
Feb 18th, 2003, 01:51 PM
Normally the pressing of the Tab key can not trapped if there is more than one control on a form that has a TabStop set to True. The attached form demonstrates how to get around that problem.

Serge
Feb 24th, 2003, 12:03 PM
Just to note one thing. Before assigning the TabStop property to False, first check if the control is not Label, Image or Line. These controls don't have TabStop property because they are being painted directly on the form.

MartinLiss
Feb 24th, 2003, 12:12 PM
Thanks Serge. The StoreTabsStops sub in the form has the following statement:


'Store the TabStop property for each control on the form. If you run into
'a control without a TabStop, just add an On Error Resume line

I probably should have just included the On error Resume Next line instead of the advice.

techyspecy
Feb 26th, 2003, 12:01 PM
Here is another way ..
Put two textboxes on the form ..



Option Explicit

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_TAB = &H9

Private Sub Text2_LostFocus()
If GetTabState Then MsgBox "You just tabbed out of Text2"
End Sub

Private Sub Text1_LostFocus()
If GetTabState Then MsgBox "You just tabbed out of Text1"
End Sub

Private Function GetTabState() As Boolean
GetTabState = False
If GetKeyState(VK_TAB) And -256 Then
GetTabState = True
End If
End Function




Simple, Effective and Efficient code ...

MartinLiss
Feb 27th, 2003, 12:00 PM
This thread got away from what I think is appropriate for the CodeBank so rather than closing it I deleted several posts. I also edited out of techyspecy's post a quote that referred to the deleted posts. If you have concerns about my having taken this action please PM me.