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: Beginner
Oct 1, 1996

Recognizing Tab Key

Question:
I have a text box that updates a memo field in Access. I would like to give the users the ability to insert tabs. The KeyDown and Keypress will not recognize the tab key.

Answer:
Inserting tab characters is a bit of a pain because the Tab is intercepted by Windows. What I would suggest that you do is to allow the user to press Control-T to put in a tab, which you can intercept (Ascii Code = 20). Then set the SelText property of the text box equal to a certain number of spaces rather than using the ASCII Tab character. It is possible to put Tab functionality into a textbox. But to do so you have to turn off the TabStop property for all controls on your form, thus breaking the ability for your users to tab from control to control. Since tabbing between controls is part of the Windows standards you should think hard about your app's need to do this before employing this sort of functionality. Code to toggle TabStop state looks like this:

Sub ChangeTabStops (flag As Integer)
'if flag = False this sub turns off all the tab stop properties on all the
'controls on Form1
'Passing flag = True turns the tab stops back on
Dim i As Integer

On Error Resume Next
  For i = 0 To Form1.Controls.Count - 1   ' Use the Controls collection
    Form1.Controls(i).TabStop = flag         'set the Tabstop property to either True or False
  Next

End Sub
If you're not happy with the default size of the Tab's space you can use the SendMessage API call along with the EM_SETTABSTOPS constant to change it. Be careful on the declare for this because the 32-bit version is a lot different than the 16-bit one.
DevX Pro
 
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