TextBox Height Resize

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
 
G

Guest

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.
 
K

Kevin Yu [MSFT]

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top