label that resizes based on text and font

J

JustinC

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?
 
M

Michael C

JustinC said:
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)
 
T

Tim Wilson

Are you actually using a Label control? If so you can set the AutoSize
property to true.
 
G

Guest

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
 
J

JustinC

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 ;-)
 

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