Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to determine TextBox width?
Message
De
21/09/2009 06:52:25
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
 
 
À
21/09/2009 06:41:31
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01425392
Message ID:
01425407
Vues:
76
>>>>>Hi,
>>>>>
>>>>>I have a TextBox control which is bound to a C32 field.
>>>>>
>>>>>How do I programatically find out the shortest width of the TextBox and make sure any 32 characters inputed will be displayed fully in the textbox?
>>>>>
>>>>>I was thinking:
>>>>>TextBox.Width = 32 * FONTMETRIC(7, TextBox.FontName, TextBox.FontSize)
>>>>>
>>>>>But FONTMETRIC(7) is crazy... for Arial font size 10, it gives me 35 about 6 time of FONTMETRIC(6)...
>>>>
>>>>Hi
>>>>Try
>>>>
>>>>WITH YourTextbox
>>>>  lcFontStyle = IIF(.FONTBOLD,"B","") + ;
>>>>   IIF(.FONTITALIC,"I","") + ;
>>>>   IIF(.FONTSTRIKETHRU,"-","") + ;
>>>>   IIF(.FONTUNDERLINE,"U","")
>>>>
>>>>  lnFontMetric = FONTMETRIC(6,.FONTNAME ,.FONTSIZE,lcFontStyle)
>>>>
>>>>.WIDTH = CEILING(TXTWIDTH(.VALUE, ;
>>>>  .FONTNAME,.FONTSIZE,lcFontStyle)+1)*lnFontMetric
>>>>
>>>>ENDWITH &&YourTextbox
>>>>
>>>
>>>I don't understand the use of TXTWIDTH in the codes, is the code suppose to change the textbox width everytime textbox.value is changed?
>>>
>>>I was looking for a way to determine a shortest fix width of TextBox which will hold any 32 chars string, For example when a form is used just to display field values in TextBox.
>>>I mean, it is possible to calculate this width without taking the string or textbox.value as a factor?
>>
>>Code above is an example from my autofitting textbox. As Sergey wrote, a minimum width is hard to determine.
>>you might do something like
>>
>>lnMax = 0
>>for lnLoop = 0 to 255
>>lnMax= MAX(lnMAX,CEILING(TXTWIDTH(REPLICATE(chr(lnloop,32),.FONTNAME,.FONTSIZE,lcFontStyle)+1))
>>endfor
>>
>>.width = lnMax*lnFontMetric
>>
>>
>>This will figure out what will be the max width you need to display 32 chars of a given font. It is overkill.
>>
>>Agnes
>
>Hi Agnes,
>
>Do you know what exactly the FontMetric(7) suppose to be? Isn't it suppose to provide what you are looping for?
>I think the loop is too much, may be just test for replicate of "W", I think this normally is the widest character in all kind of fonts.

Just run it against my loop
?lnMax*lnFontMetric,FONTMETRIC(7,.FONTNAME ,.FONTSIZE,lcFontStyle)*32
I've never searched for max, my code was only for a start.

Agnes
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform