>>>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
>>
>
>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?
It depends on what kind of font the TextBox is using. You can calculate such width for none-proportional font but for proportional font the width will depends on the content of the textbox.
--sb--