TextHeight, TextWidth
The TextHeight and TextWidth methods return the size of a supplied text string, in pixels.
Usage | nHeight = objFormOrScreen.TextWidth( cString ) nWidth = objFormOrScreen.TextHeight( cString ) |
These methods are handier versions of the TxtWidth() and FontMetric() functions. They return the size a text string will take up on a Form or on the _SCREEN, expressed in pixels. The calculation is based on the current output window's text name, size and style. TextWidth returns the length of the longest line of text, if carriage returns are included in the supplied string. TextHeight increases correctly as well, but only if the string includes linefeed characters. This is not the case with VFP 3.x, where TextWidth returns the width for the whole string, as if the carriage returns were printable characters. For VFP 3.x, use MemLines() and MLine() to parse the string into individual lines and pass them to TextWidth(). With VFP 5.0 and later, this bug has been squashed.
Example | _SCREEN.FontName = "Arial" _SCREEN.FontSize = 10 nHowWide = _SCREEN.TextWidth("How wide is my string?") && 134 nHowHigh = _SCREEN.TextHeight("How high is my string?") && 16 |
See Also | FontMetric, MemLines(), MLine(), TxtWidth(), ScaleMode |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.