Click or drag to resize

TxtWidth Function

X#
-- todo --
Returns the length of a character expression with respect to the average character width for a font.

Namespace:  XSharp.VFP
Assembly:  XSharp.VFP (in XSharp.VFP.dll) Version: 2.19
Syntax
 FUNCTION TxtWidth(
	cExpression,
	cFontName,
	nFontSize,
	cFontStyle
) AS FLOAT CLIPPER
Request Example View Source

Parameters

cExpression (Optional)
Type: Usual
Specifies a character expression for which TXTWIDTH( ) returns the length. If you include only cExpression, the length of the character expression is returned for the current font for the main X# window or the active output window. A non-proportional font always returns a value equal to the number of characters in cExpression.
Include the optional arguments cFontName, nFontSize and cFontStyle to determine the length of a character expression with a specific font, font point size, or font style.
cFontName (Optional)
Type: Usual
Specifies the name of the font. Include cFontName to return the length of a character expression with a specific font.
nFontSize (Optional)
Type: Usual
Specifies a number that corresponds to the point size of the font. Include nFontSize to return the length of a character expression with a specific point size.
cFontStyle (Optional)
Type: Usual
Specifies a special font style for the character expression. cFontStyle is a font style code specified by a character or a set of characters. The Normal font style is used if cFontStyle isn't included. The characters for each font style can be found in the remarks section.

Return Value

Type: Float
Numeric
Remarks
TXTWIDTH( ) returns the number of characters a character expression cExpression occupies, based on the average character width of a specified font (the average character width of a font is called a foxel). Use FontMetric(6) to determine the average character width of a font.
If you don't include a font in TXTWIDTH( ), the value returned by TXTWIDTH( ) is determined by the current font for the main X# window, as long as output is directed to the main X# window when TXTWIDTH( ) is issued. If output is being directed to a user-defined window, the value returned is determined by the window's current font.
CharacterFont Style
BBold
IItalic
NNormal
OOutline
QOpaque
SShadow
-Strikeout
TTransparent
UUnderline
You can include more than one character to specify a combination of font styles. For example, BI specifies a Bold Italic font style.
The following command displays a message in a Courier normal 24-point font, centered horizontally in the main X# window:
X#
1@ 25,(WCOLS( )-TXTWIDTH('Hello!','Courier ',24)* ;
2FontMetric(6,'Courier ',24)/FontMetric(6))/2  ;
3SAY 'Hello!' FONT 'Courier ',24
See Also