Click here to Skip to main content
15,663,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to resize a multi line textbox to the minimum amount it contains?

I have text streamed into a multi line textbox and want to keep this textbox to a minimum size. It will be different sizes depending on user choices but will have a constant text size.

I read the textbox height is calculated from the text size, not user choice. How does it convert the size into pixels, and is this the best way of going about it or is there a premade function to autosize the textbox?

|Thank you for your time.
Sergey Alexandrovich Kryukov 27-Mar-13 22:43pm    
Bad idea, I would say. Eventually, the number of lines will be too many to fit the screen size, what are you going to do? What's wrong with text with scroll bars? Better review your design.
lostandconfused1234 27-Mar-13 23:00pm    
Ah I think I mis-led. The user is filling in a form and this gives the summary, but depending which form the number of lines is different. I want the summary box to be as small as possible to put a large picture and whatnot below, but the user input is highly limited. They're mostly combo boxes so it will never overload with size. I just want to minimize the amount it takes
Sergey Alexandrovich Kryukov 27-Mar-13 23:26pm    
My reply is in my answer, please see.

1 solution

You need to consider the design as a whole thing. Make some reasonable size and allow the user to enter more, then the scroll bar will appear. What's wrong with that? Remember that the space does not come for free. If you take a bit more space for a control, it is taken at the expense of other controls.

After all, if a summary appears to be too long, most won't need to read it all, so the available small part will suffice, and those who would want to read it all, will rather agree to use scrolling. You can experiment with real-life text to estimate the reasonable room you need.

(By the way, I learned one of the golden rules of industrial design: if you want to present the design with some text, for prototype presentation of testing, always use some texts from real life, as realistic as possible. People who show "blah-blah" or "Lorem ipsum" usually miss a lot.)

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900