Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ampersand 2

Status
Not open for further replies.

kimtp

Programmer
Jun 15, 2002
310
US
I have a program that I would like to use the ampersand. Like A, B & C. However whenever I use it all that shows up is an underline.

Here is what I have:
Code:
 lblampersand.caption = "A, B " & chr(38)& "C."

Any ideas would be appreciated.

Kim
 
Either set

lblampersand.UseMnemonic = False

or double up your ampersands

lblampersand.caption = "A, B && C."
 
The reason for your problem is that in captions the ampersand is used to indicate that the following character is the action key for that control (i.e. the key you combine with the Ctrl key to activate the control via keyboard). To visually indicate the action key MS underlines the character in the caption. In your case it looks like just an underscore because the following character is a space.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Just to round out tracy's post: most controls that have this ability are focusable, meaning you can land on them. An example would be a command button. Hitting the alt key (that's a small correction to Tracy's post, it's not the control key) sequence will cause the control to become the current control (and also will fire its click event if it has one).

Now, labels have this keyboard activate ability, but are not focusable, meaning you can't land on them. The way that it works is that the next focusable control in the tabindex order (note that labels are one of the few non-focusable controls with a tabindex property as well) gets the focus when you invoke the alt sequence that selects that label.

The common use for this is to provide keyboard support for selecting text boxes in a data entry application. For example, if there is a label whose caption is "&First Name:" with a tabindex of 2, and then a text box txtFirstName with a tabindex of 3, then hitting Alt-F will set focus to txtFirstName, just as if you had clicked in the text box.

As a general rule, it's a good idea to include the labels in the tabindex order when setting it up, whether you're supporting alt keys or not. It makes it easier to do later.

HTH

Bob
 
Bob: you're right about the Alt key! [blush]

Here's the info from MSDN:
MSDN said:
You can use the Caption property to assign an access key to a control. In the caption, include an ampersand (&) immediately preceding the character you want to designate as an access key. The character is underlined. Press the ALT key plus the underlined character to move the focus to that control. To include an ampersand in a caption without creating an access key, include two ampersands (&&). A single ampersand is displayed in the caption and no characters are underlined.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top