JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page


You use labels for just what they sound like—to label other parts of your application. Labels usually are used to display text that cannot be edited by the user. Your code can change the text displayed by a label. Labels are based directly on the Control class:


The caption for a label is stored in the Text property. Because you can change that caption in code, labels can act a little like non-editable text boxes, displaying text and messages to the user. The TextAlign (formerly Alignment) property allows you to set the alignment of the text within the label.

Here's another interesting aspect of labels—they cannot receive the focus (that is, become the selected target of keystrokes), but you can set up mnemonic characters for them with the UseMnemonic property; just specify a mnemonic character in their caption by preceding it with a & character. In that case, when the user presses Alt and the mnemonic character, the focus goes to the control after the label (that is, the control which the label is labeling), which lets you support keyboard navigation for the many controls that don't support mnemonic characters. (For more information, see "Using Labels to Give Access Keys to Controls without Captions" later in this chapter.) You also can support images in labels with the Image property, or the Image and ImageList properties together.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor