******************************************************************************** FUNCTION TEXTWIDTH( toForm, toObject, tcText ) ******************************************************************************** * * OVERVIEW: Returns the width, in pixels, required to display a string in * the font characteristics specified for an object. * * PARAMETERS: * * toForm An object reference to the form containing toObject * toObject The object that will display tcText -- typically a label or header * tcText The string for which to return the width in pixels. * * RETURNS: The number of pixels required to display tcText. * * HISTORY: Created 05/15/02 (JME) * * COPYRIGHT: 2002, Jurix Data Corporation. * * NOTE: The function DOES NOT remove leading/trailing blanks. * LOCAL ; llFontBold, lcFontName, llFontItalic, lnFontSize, ; llFormFontBold, lcFormFontName, llFormFontItalic, lnFormFontSize, ; lnWidth * Store the font characteristics of the object displaying the string. WITH toObject llFontBold = .FontBold llFontItalic = .FontItalic lcFontName = .FontName lnFontSize = .FontSize ENDWITH * Store the font characteristics of the form (to be restored below) and * replace the form font characteristics with object font characteristics * in preparation for calling the form .TextWidth() method. WITH toForm llFormFontBold = .FontBold llFormFontItalic = .FontItalic lcFormFontName = .FontName lnFormFontSize = .FontSize .FontBold = llFontBold .FontItalic = llFontItalic .FontName = lcFontName .FontSize = lnFontSize * The .TextWidth method of the form returns the number of pixels required * to display the string in the current form font. lnWidth = .TextWidth( tcText ) * Restore the form's font characteristics. .FontBold = llFormFontBold .FontItalic = llFormFontItalic .FontName = lcFormFontName .FontSize = lnFormFontSize ENDWITH IF VARTYPE( lnWidth ) # "N" lnWidth = 0 ENDIF RETURN lnWidth ENDFUNC && TEXTWIDTH()Call this method passing an object reference to the form, an object reference to the header and the caption string to be measured, i.e.:
lnWidthInPixels = TEXTWIDTH( thisform, thisform.myGrid.Columns[ 1 ].Controls[ 1 ], "My Header Caption" )If you do not use word wrap in your headers, this should tell you the width your column needs to be to display the full string. I would use a 10 pixel (or greater) margin.