Page 1 of 1

Script to resize text to fit text box?

Posted: Thu Aug 06, 2020 6:09 pm
by cmhjon
Hi all,

I am looking for a way (via script) to look at some text in a text box and ensure the text box is wide enough to fully show all text characters within and if not decrease the text size accordingly. In this case, text boxes will contain a decimal measurement in inches. A text box could contain:

x
x.x
x.xx
x.xxx
x.xxxx
etc.

(x is a number of course)

Just figure the width based on the longest possible text string for all text boxes you say? That's great but then I run the risk of overlapping text between two neighboring text boxes.

A script is preferable but I am open to other ideas.

Thank you,
Jon :)

Re: Script to resize text to fit text box?

Posted: Thu Aug 06, 2020 6:32 pm
by stam
Hi cmhjon,

haven't tested it but think the formattedWidth would do it?
i.e.

Code: Select all

set the width of field 1 to the formattedWidth of field 1

Re: Script to resize text to fit text box?

Posted: Thu Aug 06, 2020 6:33 pm
by jmburnod
Hi Jon,
Here is a thread probably useful for you
viewtopic.php?f=7&t=30996&hilit=textsize+formattedwidth
Best regards
Jean-Marc

Re: Script to resize text to fit text box?

Posted: Thu Aug 06, 2020 8:53 pm
by dunbarx
Hi.

There have been several threads on this topic.

When you mention changing the textSize in certain cases, does that mean that there is a maximum allowable width for the field? If not, then setting the formattedWidth, as stam posted, should be fine. If so, however, and this was discussed as well, you may not want to reduce the textSize beyond what is reasonable for the user to read. It is not good practice anyway, as users are not expecting this sort of action.

So what are your limitations, if any?

Craig

Re: Script to resize text to fit text box?

Posted: Thu Aug 06, 2020 9:29 pm
by dunbarx
I found the discussion about a similar topic:
viewtopic.php?f=9&t=34247&p=192845&hili ... th#p192845

Craig