Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculating widths and heights of strings
Message
From
28/11/2005 09:23:53
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01072336
Message ID:
01072424
Views:
19
Below is a method that I wrote to determine the maximum string length based on a width. It uses a form standard method, so it must be a method of a form.
LPARAMETERS pcTextString,pnLabelWidth
LOCAL lnNdx, lcDrive, lcTest, lnStart
lnStart = ATC(":\",pcTextString)
IF lnStart > 0
*-*	Trim path
	lnStart = lnStart + 1
	lnNdx   = 0
	lcTest  = pcTextString
	lcDrive = LEFT(pcTextString,lnStart) + ".."
	DO WHILE thisform.TextWidth(pcTextString) > pnLabelWidth
		lnNdx = lnNdx + 1
		DO WHILE SUBSTR(pcTextString,lnStart+lnNdx,1) != "\" .AND. lnStart+lnNdx <= LEN(pcTextString)
			lnNdx = lnNdx + 1
		ENDDO
		IF SUBSTR(pcTextString,lnStart+lnNdx,1) != "\"
			pcTextString = lcTest
			EXIT
		ENDIF
		lcTest = lcDrive + SUBSTR(pcTextString,lnStart+lnNdx)
		IF thisform.TextWidth(lcTest) <= pnLabelWidth
			pcTextString = lcTest
			EXIT
		ENDIF
	ENDDO
ELSE
*-*	Trim text description
	pcTextString = pcTextString
ENDIF
RETURN pcTextString
You can possibly adopt this to determine how wide you need for the form.
Previous
Reply
Map
View

Click here to load this message in the networking platform