Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checkbox caption
Message
De
11/06/2008 09:17:16
 
 
À
10/06/2008 04:09:53
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:
01323055
Vues:
24
This message has been marked as the solution to the initial question of the thread.
Hi,

this code based on the GDIPlusX library should get you started.
&& 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
	
ENDFUNC
Christian
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform