Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autosize text to fit defined area

Status
Not open for further replies.

stilllwaiting

Programmer
Nov 6, 2000
17
0
0
US
I'm trying to update a current application.

The application I have now allows a user to type text into three separate text boxes which will display automatically in a preview area. As they enter text into these three text boxes, the application automatically resizes the text to make it as large as possible in the defined preview area and making it smaller as more text is entered to make sure that all the text will fit. I do this by calculating the approximate width of the characters based on font size and resizing the text appropriately.

In the update, I want to replace the three text boxes with one text area to do the same job.

I'm confident I can do the same thing using the users break lines and calculating the width and height from there, but it would be nice to allow text wrapping and not force the user to break the line themselves.

I've been researching this for a while, though and can't seem to find a way to measure the space the text is taking up if I allow wrapping.

Does anyone know of a way to measure the actual space (in pixels) a span of text is taking up?

Thanks in advance.


 
The only way I've been able to determine the size a span of text will take up is to create the span in memory (using DOM functions like createNode) and then get the width of that element.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top