Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 3

Assigning an Access Key to a TextBox Control Through a Label's Caption

Let's say that you have a TextBox representing the Department name on an entry screen. The Label to the left of the TextBox duly contains the Caption "Department."

If you put an ampersand (&) in front of the "D" in "Department," the "D" will appear underlined. When users see this, they will think, of course, that pressing Alt-d will place the cursor in the TextBox.

Unfortunately, the "D" represents an access key for the Label—and moreover, the Label is incapable of receiving focus. Figure 3.14 illustrates a Label that implements an access key for a TextBox.

A Label that implements an access key for a TextBox.
FIGURE 3.14 - A Label that implements an access key for a TextBox.

However, if the user does press the Alt-D combination, focus will fall on the control following the Label in TabIndex order. Thus you can implement an access key for a TextBox control by defining an access key on a Label that immediately precedes the TextBox control in the TabIndex order.

So in order to give an access key to a TextBox, follow these steps:

STEP BY STEP
3.4 Giving an Access Key to a TextBox
  1. Put a Label to the left of the TextBox.

  2. Make sure the Label's UserMnemonic property is True (it should be, as that's the default value).

  3. Give the Label a TabIndex that is one less than the TabIndex of the TextBox.

  4. Put an ampersand (&) in front of one of the letters in the Label's Caption. This letter will become the access key for the TextBox.

This technique works because the ampersand in the Label's caption defines an access key, as discussed above in the section on the Caption property. However when the user presses the Label's access key, the system is unable to set focus to the Label (because Labels cannot receive focus). Instead, the focus goes to the next control in the Tab order—which in this case is the TextBox that you've strategically placed to receive the focus from the Label.


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved