Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Control's width based on its value
Message
From
25/05/2000 12:23:48
 
 
To
24/05/2000 16:46:44
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00372954
Message ID:
00373225
Views:
22
Hi Mark.

>What would be the most trustful way to find width of a control based on its value, font and etc.?

This isn't as easy as it seems <g>. Here's some code I use:
lnLength = *length of the field*
with This
    lcStyle = iif(.FontBold, 'B', '') + iif(.FontItalic, 'I', '') + ;
        iif(.FontCondense, 'C', '') + iif(.FontExtend, 'E', '') + ;
        iif(.FontOutline, 'O', '') + iif(.FontShadow, 'S', '') + ;
        iif(.FontStrikethru, '-', '') + iif(.FontUnderline, 'U', '')
    lcStyle = iif(empty(lcStyle), 'N', lcStyle)
    .Width  = min(txtwidth(replicate('W', lnLength), .FontName, ;
        .FontSize, lcStyle) * fontmetric(6, .FontName, .FontSize, ;
        lcStyle) + .Margin * 2 + iif(.SpecialEffect = 0, ;
        6, 0) + 2, Thisform.Width - .Left - 5)
endwith
You'll note the use of a couple of "magical" numbers: "6" and "2". "6" is the number of pixels added to the width of a 3-D textbox (3 pixels left + 3 pixels right). "2" was determined empirically (TXTWIDTH * FONTMETRIC(6) seems to be out by 2 pixels on average).

Hope this helps.

Doug
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform