Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to determine TextBox width?
Message
De
21/09/2009 06:32:59
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
 
 
À
21/09/2009 06:15:26
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:
01425402
Vues:
58
>>>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
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform