Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checkbox caption
Message
De
12/06/2008 04:54:26
 
 
À
12/06/2008 01:03:58
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01322765
Message ID:
01323381
Vues:
23
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. && !!! 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
Christian
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform