General information
Category:
Forms & Form designer
Another way to do this:
PARAMETER cTextString
* width of edit control - width of scroll bars
nMaxWidth = _screen.ActiveForm.edit1.width -25
* Average characters for control
nLineLength = nMaxWidth / fontmetric(6)
cOutPut = ''
DO WHILE LEN(cTextString) > nLineLength
*determine the maximum number of characters that will fit on a line
cTmpString = LEFT(cTextString, nLineLength)
* find the last full word
nBreakPos = RAT(' ', cTmpString)
* bite off the chunk of text
cTmpString = LEFT(cTmpString, nBreakPos)
* add to output string
cOutput = cOutPut + cTmpString + CHR(13)+CHR(10)
* truncate the original string and repeat
cTextString = SUBST(cTextString, nBreakPos+1)
ENDDO
* use up what's left
cOutput = cOutPut + cTextString + CHR(13)+CHR(10)
* assign to control
_screen.ActiveForm.edit1.value = cOutPut
This is a rough. Some additional code may be is required.
A point of curiosity
With an Arial font, 10 pitch I get
txtwidth('ABCDEFGHIJKLMNOPQRSTUVWZYZ0123456789')/26 = 1.891
txtwidth('abcdefghijklmnopqrstuvwxyz01234567890')/26 = 1.4423
But fontmetric(6) = 6
Why?
Tevye
>Claudio,
>
>Thanks again for your help and creative ideas. Here's what I've decided to do inspired by your suggestion (and the feedback of others as well):
>
>To determine the number of rows required to display a word wrapped text string in a form of a given width, I'm going to use the GetWordNum() function of VFP 7 and build each word wrapped line one at a time. I will keep adding words to a line until txtwidth() * fontmetric( 6 ) becomes greater than the form width at which point I will start building another line. Plus I'll add some logic for handling carriage returns and linefeeds.
>
>Regards,
>Malcolm
>
>>Hi Malcom;
>>
>>I really glad to help you to find the answer of your need.
>>
>>>the edit control does not have an Autosize property. The label control has an autosize property, but its text value must be less than 256 characters.
>>
>>The fontmetric(7) gives you the maximun width (in pixels) of a single character. You can assembler your form using this like the main coordinate for your form's width.
>>
>>
>>Claudio
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only