Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to determine TextBox width?
Message
 
 
To
21/09/2009 06:15:26
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01425392
Message ID:
01425401
Views:
82
>>>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?

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--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform