Caption Property

See Also58R36C                 Example9UTB0YX>Low

Applies To

Form14TJ2LN, MDI form1ILMZQ7, check box9P3BU5, command buttonXJSPC0, data control2E1FEX3, frame1KX6ZP8, label3MNIZ8D, menuBKDT1F, option buttonJYBO08.


         Formdetermines the text displayed in the form's title bar32N908X.  When the form is minimized, this text is displayed below the form's icon529QBG.


         Controlsdetermines the text displayed in or next to a control.



[form.][control.]Caption[ = stringexpression ]


When you create a new object, its default caption is the same as the default Name2016V9P for both forms and controls.  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 key3XSY0O6 to a control.  In the caption, include an ampersand (&) immediately preceding the character you want for an access key.  The character will be underlined.  Press Alt plus the underlined character to move the focus1L3L8ZY to that control.  To include an ampersand in a caption without creating an access key, type a double ampersand (&&).  A single ampersand will appear in the caption and no characters will be underlined.

For labels, the caption is limited to 2048 characters.  For forms and all other controls that have captions, the limit is 255 characters.

To display a form caption, set the BorderStyle43RNRL property to either 1, 2, or 3.  A caption too long for the form's title bar will be clipped.

When an MDI child form is maximized within an MDI form, the child form's caption is included with the parent form's caption.


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


Data Type


See Also

Programmer's Guide:

Chapter 3, "Creating and Using Controls"

Caption Property Example

The example changes the caption on a command button each time the user clicks the button.  To try this example, paste the code into the Declarations section of a form containing a command button named Command1.  Then press F5 and click the button.

Sub Command1_Click ()
  ' Check caption, then change it.
  If Command1.Caption = "Clicked" Then
    Command1.Caption = "OK"
    Command1.Caption = "Clicked"
  End If
End Sub