Visual Basic Reference

Visual Studio 6.0

Caption Property

See Also    Example    Applies To

  • Form determines the text displayed in the Form or MDIForm object's title bar. When the form is minimized, this text is displayed below the form's icon.

  • Control determines the text displayed in or next to a control.

  • MenuLine object determines the text displayed for a Menu control or an object in the MenuItems collection.

For a Menu control, Caption is normally read/write at run time. But Caption is read-only for menus that are exposed or supplied by Visual Basic to add-ins, such as the MenuLine object.

Syntax

object.Caption [= string]

The Caption property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list. If object is omitted, the form associated with the active form module is assumed to be object.
string A string expression that evaluates to the text displayed as the caption.

Remarks

When you create a new object, its default caption is the default Name property setting. This default caption includes the object name and an integer, such as Command1 or Form1. For a more descriptive label, set the Caption property.

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.

A Label controls caption size is unlimited. For forms and all other controls that have captions, the limit is 255 characters.

To display the caption for a form, set the BorderStyle property to either Fixed Single (1 or vbFixedSingle), Sizable (2 or vbSizable), or Fixed Dialog (3 or vbFixedDialog). A caption too long for the form's title bar is clipped. When an MDI child form is maximized within an MDIForm object, the child form's caption is included in the parent form's caption.

Tip   For a label, set the AutoSize property to True to automatically resize the control to fit its caption.

Show: