Textbox Problem

  • Thread starter Thread starter DotNetJunkie
  • Start date Start date
D

DotNetJunkie

Hi NG,

I want to pass a very long string to a multilined TextBox. After doing this,
I want to resize the TextBox vertically, so that the text fits into the
TextBox exactly. Any ideas? I need it for a custom MessageBox.

Thank you

Rudi
 
Hi,

I do not understand clearly what you are trying to do, but I can give you a
few suggestion, first of all, if it's for a MessageBox you should use a
Label instead of a TextBox , use the TextBox only if the user can change the
Text.
You can format the text of the message, I remember I did that once in
javascript you could insert \n at certain points to force a correct display
of the message, later you can know how many lines the message has by
counting the \n.

Hope this help,
 
Rudi,

I think that the calculation for this might not be so simple. You can probably call the MeasureString method on the Graphics class, and then check to see how many lines you will need based on the length of your text (you can approximate based on the number of pixels long, and all fonts have a consistent height). However, this is not exact. If you want to be exact, then you need to have an algorithm that will separate the words and see how many you can fit on each line, and then figure out how many lines you need based on the words.

Hope this helps.

-Nicholas Paldino [.NET/C# MVP]
-nick{dot]paldino=at^exisconsulting-dot?com
 
Back
Top