*... m.loFormat.Trimming = IIF(lnTrimMode=StringTrimmingEllipsisPath,StringTrimmingEllipsisCharacter,tnTrimMode) *...*but this not perfect
*calculate the gaps for some objects *this is what looks closest on my comp, (using your approach) *one might add an extra pixel of width if one likes a gap on the right border. *its mianly done with a string [i[i[i[i[i[i[i]]]]]]]ppppppppppppppppppppppppppppppppppp as caption *I run trough all numbers of i so that I found some "bad" states DO CASE CASE loControl.BASECLASS='Label' m.lnWidth = m.loControl.WIDTH-8 m.lnHeight = m.loControl.HEIGHT CASE loControl.BASECLASS='Commandbutton' m.lnWidth = m.loControl.WIDTH-13 m.lnHeight = m.loControl.HEIGHT CASE loControl.BASECLASS='Checkbox' AND toObject.STYLE=0 m.lnWidth = m.loControl.WIDTH-22 m.lnHeight = m.loControl.HEIGHT CASE loControl.BASECLASS='Checkbox' m.lnWidth = m.loControl.WIDTH-13 m.lnHeight = m.loControl.HEIGHT CASE loControl.BASECLASS='Optionbutton' AND toObject.STYLE=0 m.lnWidth = m.loControl.WIDTH-22 m.lnHeight = m.loControl.HEIGHT CASE loControl.BASECLASS='Optionbutton' m.lnWidth = m.loControl.WIDTH-13 m.lnHeight = m.loControl.HEIGHT CASE loControl.BASECLASS='Header' m.lnWidth = m.loControl.PARENT.WIDTH-8 m.lnHeight = m.loControl.PARENT.PARENT.HEADERHEIGHT OTHERWISE RETURN m.lcText ENDCASE>Hello Agnes,
>#DEFINE CHECKBOXMARGIN_STYLE_0 16 >#DEFINE CHECKBOXMARGIN_STYLE_1 4 > >#DEFINE StringTrimmingNone 0 >#DEFINE StringTrimmingCharacter 1 >#DEFINE StringTrimmingWord 2 >#DEFINE StringTrimmingEllipsisCharacter 3 >#DEFINE StringTrimmingEllipsisWord 4 >#DEFINE StringTrimmingEllipsisPath 5 > >FUNCTION FitTextToControl > LPARAMETERS loControl, 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 lcText, lnCharCount, lnOrigTrimMode > > m.lnCharCount = 0 > m.lnWidth = m.loControl.Width > m.lnHeight = m.loControl.Height > > DO CASE > CASE m.loControl.BaseClass = 'Checkbox' > m.lnWidth = m.lnWidth - IIF(m.loControl.Style = 0, CHECKBOXMARGIN_STYLE_0, CHECKBOXMARGIN_STYLE_1) > CASE m.loControl.BaseClass = 'Combobox' > && ... > CASE m.loControl.BaseClass = 'Label' > && ... > ENDCASE > > m.lnOrigTrimMode = m.lnTrimMode > IF m.lnTrimMode = StringTrimmingEllipsisPath > m.lnTrimMode = StringTrimmingCharacter > ENDIF > > WITH _SCREEN.System.Drawing > m.loFont = .Font.New(m.loControl.Fontname, m.loControl.Fontsize, 0, .GraphicsUnit.Point) > 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 = .F. && !!! this gives better results !!! > 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 = m.lnTrimMode > * Measure the String > m.loGfx.MeasureString(m.lcText, m.loFont, m.loRect, m.loFormat, @m.lnCharCount) > ENDWITH > > DO CASE > CASE LEN(m.lcText) <= m.lnCharCount > RETURN m.lcText > CASE INLIST(m.lnOrigTrimMode, StringTrimmingEllipsisCharacter, StringTrimmingEllipsisWord) > RETURN SUBSTR(m.lcText, 1, m.lnCharCount) + '...' > CASE m.lnOrigTrimMode = StringTrimmingEllipsisPath > RETURN DISPLAYPATH(m.lcText, m.lnCharCount) > OTHERWISE > RETURN SUBSTR(m.lcText, 1, m.lnCharCount) > ENDCASE > >ENDFUNC >>