Textbox Length

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

I need to set TextBox length based on the text length in the TextBox, so the
entire text in the box is visible. Can anyone point me to an info on how to
accomplish this?

Thank You


Peter
 
Peter, try something like this:

using (Graphics g = textBox1.CreateGraphics())
{
SizeF s = g.MeasureString(textBox1.Text, textBox1.Font);
textBox1.Size = new Size((int) s.Width, (int) s.Height);
}

Hope it helps,
Thi
 
Truong Hong Thi said:
Peter, try something like this:

using (Graphics g = textBox1.CreateGraphics())
{
SizeF s = g.MeasureString(textBox1.Text, textBox1.Font);
textBox1.Size = new Size((int) s.Width, (int) s.Height);
}

Hope it helps,
Thi

Thank You very much, this works
 
Back
Top