Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determing form size necessary to display arbitrary text
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00575284
Message ID:
00576151
Vues:
40
Tevye,

Thanks for your ideas. Dragan Nedeljkovich has posted a program called ALERT.PRG that claims to do what I'm looking for and what you were describing.

As for your 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

The numbers look OK to me. txtwidth() returns a value in 'foxel's. fontmetric() returns a value in pixels (i.e. the average char will be 6 pixels wide). The reason that your txtwidth() values are much greater than 1 char is that you should be dividing by 36 (because of the digits), not 26. Your example with uppercase letters is also missing a '0' (zero). Finally, the reason that the lowercase string has 'thinner' (for lack of a better description) char widths is because Arial is a proportional font and lowercase letters tend to me shorter in width than their uppercase equivalents.

Thanks again for your help!
Malcolm


>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.
>
>
>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
Malcolm Greene
Brooks-Durham
mgreene@bdurham.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform