LPARAMETERS tcMessage * *-- The width and height of the font will be calculated with the fontmetric *-- function. We first calculate the average width / height of one character. lnAvgWidth = FONTMETRIC( 6, THIS.edtMessage.FONTNAME, THIS.edtMessage.FONTSIZE, "N") lnAvgHeight = FONTMETRIC( 1, THIS.edtMessage.FONTNAME, THIS.edtMessage.FONTSIZE, "N") * *-- The lines of the text are the occurances of the CHR(13) return string. lnLinesCount = OCCURS(CHR(13), tcMessage) + 1 * *-- Get the line with the longest text. lnMaxLenght = 0 lnLastpos = 1 tcMessage = tcMessage + CHR(13) FOR ln = 1 TO lnLinesCount lcItem = SUBST(tcMessage, lnLastPos, AT(CHR(13), tcMessage, ln) - lnLastPos) * *-- Is the number of chars of the longest line. lnMaxLenght = MAX(lnMaxLenght, LEN(lcItem)) lnLastPos = AT(CHR(13), tcMessage, ln) + 1 ENDFOR * *-- Add an empty line at the beginning and at the end of the text if the text has only one line. IF lnLinesCount = 1 THIS.edtMessage.Value = SPACE(1) + CHR(13) + ; tcMessage + CHR(13) + SPACE(1) + CHR(13) ELSE THIS.edtMessage.Value = tcMessage ENDIF * *-- The lines count must be at least three lines. lnLinesCount = MAX(lnLinesCount,3) * *-- Adjust the size of the label we add one to be sure to have enough space. THIS.edtMessage.HEIGHT = lnAvgHeight * lnLinesCount + lnAvgHeight * *-- Is the number of chars of the longest line. *-- Adjust the size of the label we add 25 to be sure to have enough space, *-- think about capitalized text. THIS.edtMessage.WIDTH = lnAvgWidth * lnMaxLenght + lnAvgWidth + 50 *