473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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 2522
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Peter Larsen [] | last post by:
Hi, I have two questions related to the Label control. How do i prevent the label from expand the canvas into 2 lines (word wrap) ?? At the moment i set AutoSize to false (to prevent the word...
0
by: Kevin McKinley | last post by:
Below i've put the code for a program that i wrote. I need help on lines 384-403. If you run this program you will notice on the first tab when have it produce an answer the $ is surrounded with...
0
by: Guilherme Polo | last post by:
On Wed, Sep 3, 2008 at 8:57 PM, Kevin McKinley <kem1723@yahoo.comwrote: Come on.. "help on lines 384-403", that is not a good way to look for help. You are supposed to post some minimal code that...
6
by: Miro | last post by:
Is there a way to / or a mathematical formula to see if a font size is 'too big' for a label. I have a label that is docked to 'fill' a form, and I want to resize that font based on the width...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.