Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Auto-sizing without being in design mode?
Message
 
À
01/07/2008 14:48:30
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Divers
Thread ID:
01327956
Message ID:
01328031
Vues:
12
>>
>>You can calculate the size of the word when rendered in a specified font using:
>>
>>FONTMETRIC(6,"<font name>",<font size>, <font style>) * TXTWIDTH("<text string>","<font name>",<font size>, <font style>)
>>
>
>Hi Paul,
>
>I thought that was what I was doing with the len() / len(), and then setting the width * (len() / len()).


Not quite. The problem is that most of the fonts you use today are proportional width. That means that a W is a fair bit wider than an I. Changing the width of the label based on the ratio of the number of letters assumes that the average width of the letters in each string are the same. As you have observed, sometimes they are not.

The code above combines two VFP functions to get the actual size of the text string as rendered in a given font.
FONTMETRIC(6,...) returns the average character width of characters in the specified font.
TXTWIDTH() returns the length of a given string in "average font widths".

Taken together, this will give you a much more accurate pixel size to render a string.
Paul R. Moon
Business Software Solutions
paul@businessoftware.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform