Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Label

The Label Control is a more modern version of the @ … SAY command, with added features that allow its participation in the event loop.

Property

Value

Purpose

AutoSize

Numeric

Tells the Label control to resize itself automatically to fit the text specified with Caption.

Caption

Character

Up to 256 characters to be displayed. Preceding a character with "\<" causes that character to act as an "access" or "hot" key, moving focus to the next control beyond the label in tab order. This is a neat solution for providing accelerator keys to those controls lacking a Caption.

WordWrap

Numeric

Causes the Caption text to be wrapped onto multiple lines with a fixed Width property. Even with AutoSize set .T., the Height of the Label control does not change to accommodate the wrapped text.

While similar to the @ … SAYs of old, the label is a full participant in the event loop with MouseMove, MouseUp, MouseDown, Click and Drag-related events. Like most text-based controls, it has a whole slew of properties that can be modified at runtime, including a bunch of Font properties: FontName, FontSize, FontOutline, FontStrikeThru, FontThis and FontThat. Unlike the @ …SAYs of old, it does not require a nuclear physicist to calculate the location of the old text, erase it, and place new text in its place at runtime—just change the value of Caption, and the control handles it automatically.

Label does lack some features it might be nice to have in a read-only control, such as the ability to bind to an underlying data source. Most solutions we’ve seen involve using Text boxes with their colors tweaked and Enabled set to .F.

Example

oForm.AddObject("lblMyText","Label")
WITH oForm.lblMyText
  .Top = 20
  .AutoSize = .T.
  .FontName = "Times New Roman"
  .FontSize = 18
  .FontItalic = .T.
  .Caption = "Hello, World!"
  .ForeColor = 4259584
  .Visible = .T.
ENDWITH

See Also

AutoSize, Caption, TextBox, WordWrap