471,610 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

label that resizes based on text and font

Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?

Feb 21 '06 #1
4 2485
"JustinC" <ju***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?
You need to use the graphics object and the MeasureString or MeasureText
method (I can't rememeber exactly what it's called)

Feb 21 '06 #2
Are you actually using a Label control? If so you can set the AutoSize
property to true.

--
Tim Wilson
..NET Compact Framework MVP

"JustinC" <ju***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?

Feb 21 '06 #3
Hi Justin,
you can set the AutoSize property of the label to true, this way it will
laways resize to fit in the complete string.

Hope that helps
Mark Dawson
--
http://www.markdawson.org
"JustinC" wrote:
Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?

Feb 21 '06 #4
I was able to accomplish what I wanted using the AutoSize, but first
setting a maximum size. This was needed because I had multiple panels
within one larger panel. So the AutoSize caused each control to not
just become to correct width, but to expand to the height of the parent
control which was way too big.

I had to pick a super high number for the maximum width because I don't
want a maximum width, only a max height. Maybe this is something that
can be added in the next .NET framework release ;-)

Feb 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

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.