&& prerequisites DO system.app && initialize GDIPlusX somewhere
&& usage example Checkbox::SetCaption LPARAMETERS lcText THIS.Caption = FitTextToCheckbox(THIS, lcText, StringTrimmingEllipsisCharacter)
#DEFINE CHECKBOXWIDTHPLUSTEXTMARGINS 14 #DEFINE StringTrimmingNone 0 #DEFINE StringTrimmingCharacter 1 #DEFINE StringTrimmingWord 2 #DEFINE StringTrimmingEllipsisCharacter 3 #DEFINE StringTrimmingEllipsisWord 4 #DEFINE StringTrimmingEllipsisPath 5 FUNCTION FitTextToCheckbox LPARAMETERS loCheckBox, lcText, lnTrimMode LOCAL lnHeight, lnWidth LOCAL loFont as xfcFont LOCAL loBmp as xfcBitmap LOCAL loGfx AS xfcGraphics LOCAL loFormat AS xfcStringFormat LOCAL loSize AS xfcSize, loRect as xfcSize LOCAL lnCharCount m.lnCharCount = 0 m.lnWidth = m.loCheckBox.Width - CHECKBOXWIDTHPLUSTEXTMARGINS m.lnHeight = m.loCheckBox.Height WITH _SCREEN.System.Drawing m.loFont = .Font.New(m.loCheckBox.Fontname, m.loCheckBox.Fontsize, 0, .GraphicsUnit.Point) && 0 = FontStyle is missing - complement .... m.loBmp = .Bitmap.New(1,1) * Retrieve the graphics object. m.loGfx = .Graphics.FromImage(m.loBmp) m.loGfx.InterpolationMode = .Drawing2D.InterpolationMode.NearestNeighbor m.loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias m.loGfx.UsePrecision = .T. m.loRect = .Size.New(m.lnWidth, m.lnHeight) m.loFormat = .StringFormat.GenericTypographic m.loFormat.ALIGNMENT = .Stringalignment.Near m.loFormat.Linealignment = .Stringalignment.Near m.loFormat.Trimming = lnTrimMode * Measure the String m.loGfx.MeasureString(m.lcText, m.loFont, m.loRect, m.loFormat, @m.lnCharCount) ENDWITH IF INLIST(m.lnTrimMode, StringTrimmingEllipsisCharacter, StringTrimmingEllipsisWord) AND ; LEN(m.lcText) > m.lnCharCount RETURN SUBSTR(m.lcText, 1, m.lnCharCount) + '...' ELSE RETURN SUBSTR(m.lcText, 1, m.lnCharCount) ENDIF ENDFUNCChristian