Textbox Length

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
 
T

Truong Hong Thi

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
 
P

Peter

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
 

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