Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Text box according to text width
Message
From
22/09/2014 18:54:10
 
 
To
22/09/2014 18:07:35
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01607999
Message ID:
01608025
Views:
71
* UPDATE *

To follow up: I created some test code that uses this technique and compared it to the technique in Doug's paper. In every case I tested, the "Label" technique returned a value 2 higher than Doug's. With an empty string as the parameter Doug's method returned 0, the Label technique returns 2.

One thing I'm not sure of: Textboxes support a .FontCharSet property. That does not seem to be explicitly supported by TXTWIDTH() / FONTMETRIC(). I tried a few exotic tests but ones that were "legal" on my system still returned an offset of 2. Maybe users of non-Western character sets might see other differences.

* UPDATE END *

Have you considered using a Label instead, so you can take advantage of its .Autosize property?

If you have to use a Textbox, you might still be able to leverage a Label:

- Instanciate a label
- Make all of its .Font* properties the same as your Textbox
- Make its .AutoSize = .T.
- Make its .Value the same as your Textbox
- Read its current width
- Make your Textbox that same width (probably plus a few pixels, you'd need to experiment)

>Tore,
>
>Thanks. This is going t take a while!
>
>Yossi
>
>>This is actually harder to do, than you may immediately think. Check http://doughennig.com/papers/..%5CPub%5CGDIPlusX.pdf, search for "Measuring text".
>>
>>>Hi All:
>>>
>>>I have a class to which I pass a string to be a value for a text box in the class. I then want to adjust the width of the text box so that it is the width of the text string. How do I convert text string width to form control width?
>>>
>>>Thanks,
>>>
>>>Yossi
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform