Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checkbox caption
Message
From
11/06/2008 09:17:16
 
 
To
10/06/2008 04:09:53
Lutz Scheffler (Online)
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01322765
Message ID:
01323055
Views:
23
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform