Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 16: Text-Based Controls Visual C++ and MFC Fundamentals



  1. Return to MSVC


16.1.3..Static Labels.........................................................................................


Another type of label you can add to a form or dialog box consists of clicking the Static
Text button from the Controls toolbar and clicking on the host. The Static Text control is
based on the CStatic class.

A user cannot directly change any aspect of a label. For this reason, you will usually not
be concerned with a label's IDentifier. In fact, as we will see in this lesson, all controls
that are static type have an identifier called IDC_STATIC. If, for any reason, you want to
refer to a label in your code, you must first change its identifier from IDC_STATIC to
something else.

As stated already, the most important aspect of a label is the text it displays. This is the
Caption property. If the label is used to identify another control, you can help the user
access that control using an indicator called an access key. An access key is a underlined
letter on the label so that, when clicked, it gives access to the accompanying control. To
create an access key, choose a letter on the label and precede it with the ampersand
character “&”. Form example L&etter would produce Letter. When there are many
access keys on a form or dialog box, you should make sure that no two access keys are
the same. That is, you should not use the same letter on various labels, although this is
allowed. Because you can forget to follow this rule, after creating the access keys, you
can ask Visual Studio to check for access key duplicates. To do this, right-click the form
or dialog box and click Check Mnemonics:
Free download pdf