Code: Select all
STATIC FUNCTION XSample_186()
/* This example uses DC_FormatMemoToWidth() to perfectly
fit memo text into an object based on its font */
LOCAL cText, GetList[0], GetOptions, nWidth, cFont, cOutString, oMemo, oButton
nWidth := 640
cFont := Pad('12.Courier',40)
TEXT INTO cText WRAP
Now is the time for all good men to come to the aid of their country.
The quick red fox jumped over the lazy dog's back.
When in the course of human events it becomes necessary to Narfel the Garthog, then let the Narfelling begin.
ENDTEXT
cOutString := cText
@ 1,0 DCSAY 'Width (in pixels)' GET nWidth PICTURE '999'
@ 2,0 DCSAY ' Font' GET cFont POPUP {|c|DC_PopFont(c)}
@ 3,0 DCMULTILINE cOutString SIZE 70,14 ;
FONT Alltrim(cFont) OBJECT oMemo
@18,0 DCPUSHBUTTON CAPTION 'Format Text' SIZE 12,1.2 ;
OBJECT oButton ;
ACTION {||cOutString := DC_FormatMemoToWidth(cText,nWidth,cFont), ;
DC_GetRefresh(GetList), ;
oMemo:setFontCompoundName(Alltrim(cFont))}
DCGETOPTIONS SAYWIDTH 150 SAYRIGHTBOTTOM
DCREAD GUI FIT TITLE 'String Format Test' ;
OPTIONS GetOptions ;
EVAL {||PostAppEvent(xbeP_Activate,,,oButton)}
RETURN nil
*** END OF EXAMPLE ***