TextBox Height Resize

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

I want to resize my textbox base on the text in it.
Ways:
1) MeasureText - quite wrong
2) Detect VScroll - BUT HOW?
3).....

Please advice
 
If you want to adjust the height based on the size of the Font, try:

textBox1.Size = new Size(100, Font.Height+10);

and set the MultiLine property to true.
 
Hi Tamir,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need adjust the size of the TextBox
according to the string in it. If there is any misunderstanding, please
feel free to let me know.

We can use Graphics.MeasureString method to get the size for a particular
string and font. And then change the size of the TextBox. Here, I have
written some sample code for you. HTH.

Graphics g = this.textBox1.CreateGraphics();
SizeF s = g.MeasureString(this.textBox1.Text, this.textBox1.Font);
this.textBox1.Width = Convert.ToInt32(s.Width);
this.textBox1.Height = Convert.ToInt32(s.Height);

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top