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

Important Properties of the Label Control

Some notable properties of the Label are listed here:

Use the Alignment property to align text inside the Label—left-, right-, or center-aligned, or not aligned (None).

The Appearance, BackStyle, and BorderStyle properties together help determine the general appearance of the Label. For instance, if you leave Appearance at its default setting of 1-3d, set BackColor to vbWhite, and set BorderStyle to Fixed Single, you can give the Label the same look as that of a TextBox. BackStyle is normally Opaque, but if you set it to Transparent, whatever is on the underlying form will show through and underlie the text in the Label's Caption

  • Use the AutoSize and WordWrap properties to determine how the Label displays lengthy text in its Caption. If you set the AutoSize property of the Label to True (default is False), the Label automatically shrinks or stretches to the exact size needed to display the text. The WordWrap property determines whether or not an autosized Label changes size in a horizontal direction (WordWrap = False, its default value) or in a vertical direction (WordWrap = True). Remember, WordWrap has an effect only if you first set AutoSize to True.
  • The Label's Default property, Caption, holds the text that is visible to the user on the Label's surface. You can change Caption at runtime. As noted in previous sections, putting an ampersand character (&) in front of a letter in the Caption will turn that letter into an access key for the control (usually a TextBox) that immediately follows the Label in the TabIndex order. Since Caption is the Label's Default property, code such as

    lblName = "Name"

    would have the effect of setting the Label control's Caption to "Name.

NOTE: Visually Displaying an Ampersand in a Caption So what if you want an ampersnd in a Label's caption to really display as an ampersand—and not to function as an access key? No problem: Just set the Label's UseMnemonic property to False. This property's default value of True indicates that an ampersand will define an access key.

You can also use "&&" to display a single ampersand. Using this second method, you could leave UseMnemonic with a value of True and place a single ampersand before another letter in the Caption to define an access key.

Note that although many controls have a Caption property, only the Label features the UseMnemonic property.



<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved