471,319 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Textbox Length

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

Feb 7 '06 #1
3 9840
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

Feb 7 '06 #2

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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
Feb 7 '06 #3
That's very helpful and instructive... thanks!
"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

Feb 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Ramsin Savra | last post: by
6 posts views Thread by Stuart Ferguson | last post: by
8 posts views Thread by nil | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.