Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate width of the caption
Message
 
 
To
14/12/2018 14:48:01
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01664474
Message ID:
01664492
Views:
43
>>>>Hi,
>>>>
>>>>Simplified example.
>>>>I have a check box on a form. The caption of the check box could change (it is data driven). And if the caption is longer than what I set at design time, I want to widen the form. Question: how do you calculate the width or length of a string?
>>>>
>>>>For example, default caption of a check box: "Company". And it may change (at run-time) to being "Company Name". I need to calculate by how much to increase the width when the caption is longer.
>>>>
>>>>TIA
>>>
>>>At design, add a width_assign() method. Set autosize = .t..
>>>
>>>In the Init() event, save nWidth as startup width. In width_assign(), intercept the new value and adjust up/down based on new width to nWidth comparison, and re-save nWidth.
>>>
>>>You'll need the nWidth value to know how it's changed as there's a feature-not-a-bug in VFP that accesses to left, top, width, height will also call assign code as well. There are times the "new width" will be the old width re-stored for some feature-not-a-bug reason.
>>>
>>>You can create a custom class for this and use it wherever you need this resize ability. You can also create a discriminating class which will behave in one of N ways based on an nType setting, where nType=1 means resize form, nType=2 means reduce/enlarge font size, etc.
>>
>>Thank you for your input. My question was (kind of) simplified. The actual form where I need to make not only form width adjustment but also the left position of 30 check boxes (the form has 30 check boxes). And the suggestion to use the txtwidth() and the fontmetric() provided solution.
>
>Autosize is a better solution. You can set nWidth at design time and adjust accordingly.
>
>If you have N controls and you need to adjust based on the max, then set each checkbox's own nSize property, and call a function to iterate and find the max and use it for the aggregate nSize.

Thank you. I may look into this approach.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform