Hallo Christian,
you have changed the UsePrecision to .F. to improve the PathEllipse problem?
Changed nothing on my comp. Still no ellipsis in path, the call to MeasureString returns len(lcText)
What mostly works is
m.loFormat.Trimming = IIF(lnTrimMode=StringTrimmingEllipsisPath,StringTrimmingEllipsisCharacter,tnTrimMode)
*but this not perfect
Anyway some improvements.
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,
>
>here is an updated version, which fixes the Path elipsis problem.
>
>The margins of the individual controls have to be figured out by trial and error.
>
>
>#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.
> 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
>
>
>Christian
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord
Weeks of programming can save you hours of planning.
OffThere is no place like [::1]