Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto-sizing without being in design mode?
Message
 
To
01/07/2008 14:48:30
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Miscellaneous
Thread ID:
01327956
Message ID:
01328031
Views:
11
>>
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform