TEXTREC Method (System)
Description
Calculates the width and height needed to display a specified string.
Syntax
TextRect = Exec_Method( "SYSTEM", "TEXTRECT", ObjectID, TextParams )
Parameters
Name | Required | Description |
---|---|---|
ObjectID | No | Fully qualified ID of a form or control. If passed the calculation uses the FONT and CLIENTSIZE of the object for the calculation. |
TextParams | See Description | An @fm-delimited array specifying the parameters for the calculation. <1> Text for the calculation (CRLF delimited for multiple lines) - Required <2> DrawText flags. A bitmask integer containing flags that control how the text should be drawn - Optional <3> Maximum width of the rectangle (only used if ObjectID is not specified) – Optional <4> FONT (@svm delimited) to use for the calculation rectangle (only used if ObjectID is not specified) – Optional |
Returns
The @fm-delimited width and height of the calculated rectangle:
<1> Width
<2> Height
If ObjectID was passed the returned values will be scaled according to its SCALEUNITS property. If an object is not passed then the Maximum Width and FONT fields in the TextParams parameter are assumed to be in PIXEL coordinates. The caller is responsible for scaling them as necessary.
Remarks
Constants for use with the TextParams argument can be found in the PS_SYSTEM_EQUATES insert record.
This method uses the Windows API DrawText function internally to perform the calculation - further information regarding DrawText may be found on the MSDN website. Constants for the DrawText flags can be found in the MSWIN_DRAWTEXT_EQUATES (The DT_CALCRECT$ bit is always set internally by this method so there is no need to specify it yourself).
Example
//// Example - calculate the size of the area needed to display // //// a multiline text string on a STATIC text control// $Insert PS_System_Equates $Insert MSWin_DrawText_Equates $Insert RTI_Text_Equates Text = "Line 1" : CRLF$ : : "Line 2, and more text on the end" ObjectID = @window : ".TXT_FOO" TextParams = "" TextParams<PS_TP_POS_TEXT$> = Text TextParams<PS_TP_POS_DTFLAGS$> = DT_WORDBREAK$ TextRect = Exec_Method( "SYSTEM", ObjectID, TextParams )
See Also
Common GUI FONT property.