Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 19, 1997

Generating a "Real" Tab in a Text Box

Here's the code I used to trap the Tab key and use it to generate a "real" tab in a text box:
 ' Trap the tab key to allow tabs in a text box 
' This function should be called by the lostFocus 
' event for the control that needs to snag the tab 
' Parameters: 
' txtControl text box control 

' Setting keyboard info 
Declare Function GetKeyState% Lib "User" _ 
(ByVal nVirtKey%) 

' Virtual key values 
Global Const VK_TAB = &H9 

Sub snagTab (txtControl As Control) 
Dim retVal As Integer, currSelStart As Long 
retVal = GetKeyState(VK_TAB) 

If retVal = -128 Or retVal = -127 Then 
' tab key pressed 
currSelStart = txtControl.SelStart 
If currSelStart = 0 Then 
txtControl.Text = Chr$(9) & txtControl.Text 
Else 
txtControl.Text = Left(txtControl.Text, _ 
currSelStart) & Chr$(9) & _ 
Mid(txtControl.Text, currSelStart + 1) 
End If
' Change the focus back to this control and 
' reset the current insert point to past 
' the new "tab" 
txtControl.SetFocus 
txtControl.SelStart = currSelStart + 1 
End If  

End Sub 
Deborah Kurata
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date