1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Display the & (ampersand) Character on Labels and Buttons
Why is "Me & You" displayed as "Me _You"?

By , About.com Guide

By Windows design, accelerator keys enable the user to access a menu command from the keyboard by pressing Alt along the appropriate letter, indicated in your code by the preceding ampersand (&). The character after the and sign (&) appears underlined in the menu.

How to Specify the Shortcut (Accelerator) Key?

To specify "D" as the shortcut for the menu item with the caption "Me and Delphi" just place the "&" in front of "D", as in: "Me and &Delphi".

How to actually display the "&" character?

In the example above, if you want the caption to be "Me & Delphi" - where "and" is replaced by the and sign "&" - you need to use two and signs, as in:

"Me && Delphi"

By placing two ampesands together - you state that the character following the first one is *not* used as the accelerator - rather you actually want to get it (only one) displayed.

Note: "&&&" (or any similar combination) will *not* transfor the "&" sign into an accelerator.

The TLabel control and the ShowAccelChar and FocusControl properties

The "&" character has one more important role in designing the user interface.

Delphi's TLabel control exposes two interesting properties, FocusControl and ShowAccelChar.

When ShowAccelChar is true, any character preceded by an ampersand (&) appears underlined. If the FocusControl property is set, the windowed control specified by the FocusControl property receives input focus when the user types that underlined character.
When ShowAccelChar is false, the value of the FocusControl property is not used.

Delphi tips navigator:
» Parsing Command Line Parameters with Delphi
« Delphi's NIL value and the Assigned RTL Function

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TLabel, TStaticText
  6. How to Display the & (ampersand) Character on Delphi Labels and Buttons

©2010 About.com, a part of The New York Times Company.

All rights reserved.