I was reviewing some of my old code and I have a method that statically resizes the height of a textbox control at runtime based on the clients screen width. So there were hardocded values if screen resolution is say “1280×800” then the texbox’s height is going to be 475px. OK I get it… BAD It was semi-OK a few years ago with the fewer number of screen resolutions and CRT monitors, but not now for a number of reasons.
I have gotten much better with JavaScript and a bit better with jQuery and am looking for a solution that can resize the height of the textbox containing some text from the database based on the overall width of the containing DIV which is sized to 100% of the client’s screen width. That means wider screens need a smaller height, and less wide screens need a larger height.
I want to do this dynamically if possible. My last resort is to fix the containing control’s width which should dicate a fixed height, but I would rather the text control span the full 100% of the page.
Any suggestions are appreciated. Thanks!
That sounds like the equivalent of retrieving the text metrics before you render it to the display. I can think of ways that is done in Win Forms but in the browser… I could only think of presenting the text in an equivalently sized div (taking into account the padding in the textbox) and grabbing the rendered size, removing the div (you could do this somewhat invisibly as the page loaded) and applying the results to your textbox.